Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform and AWS: No Configuration Files Found Error

I am writing a small script that takes a small file from my local machine and puts it into an AWS S3 bucket.

My terraform.tf:

provider "aws" {
  region  = "us-east-1"
  version = "~> 1.6"
}
    
terraform {
  backend "s3" {
    bucket     = "${var.bucket_testing}"
    kms_key_id = "arn:aws:kms:us-east-1:12345678900:key/12312313ed-34sd-6sfa-90cvs-1234asdfasd"
    key     = "testexport/exportFile.tfstate"
    region  = "us-east-1"
    encrypt = true
  }
}
    
data "aws_s3_bucket" "pr-ip" {
  bucket = "${var.bucket_testing}"
}
    
resource "aws_s3_bucket_object" "put_file" {
  bucket = "${data.aws_s3_bucket.pr-ip.id}"
  key    = "${var.file_path}/${var.file_name}"
  source = "src/Datafile.txt"
  etag = "${md5(file("src/Datafile.txt"))}"
    
  kms_key_id = "arn:aws:kms:us-east-1:12345678900:key/12312313ed-34sd-6sfa-90cvs-1234asdfasd"
  server_side_encryption = "aws:kms"
}

However, when I init:

terraform init

#=>

Terraform initialized in an empty directory!
    
The directory has no Terraform configuration files. You may begin working with Terraform immediately by creating Terraform configuration files.

and then try to apply:

terraform apply

#=>

Error: No configuration files found!
    
Apply requires configuration to be present. Applying without a configuration would mark everything for destruction, which is normally not what is desired. If you would like to destroy everything, please run 'terraform destroy' instead which does not require any configuration files.

I get the error above. Also, I have setup my default AWS Access Key ID and value.

What can I do?

like image 811
Arpan Avatar asked Sep 16 '18 07:09

Arpan


1 Answers

This error means that you have run the command in the wrong place. You have to be in the directory that contains your configuration files, so before running init or apply you have to cd to your Terraform project folder.

like image 152
Alexander Avatar answered Oct 06 '22 18:10

Alexander