Terraform and AWS: No Configuration Files Found Error

44,189

Solution 1

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.

Solution 2

Error: No configuration files found!

The above error arises when you are not present in the folder, which contains your configuration file. To remediate the situation you can create a .tf in your project folder you will be working. Note - An empty .tf will also eliminate the error, but will be of limited use as it does not contain provider info. See the example below:-

provider "aws" {
    region = "us-east" #Below value will be asked when the terraform apply command is executed if not provided here
   }
 

So, In order for the successful execution of the terraform apply command you need to make sure the below points:-

  1. You need to be present in your terraform project folder (Can be any directory).
  2. Must contain .tf preferably should contain terraform provider info.
  3. Execute terraform init to initialize the backend & provider plugin.
  4. you are now good to execute terraform apply (without any no config error)
Share:
44,189
Arpan
Author by

Arpan

Updated on October 03, 2021

Comments

  • Arpan
    Arpan over 2 years

    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?

  • Arpan
    Arpan over 5 years
    thats what I did .. so my .tf files are in a folder project1 .. so I cd project1 and then run terraform init and then did the terraform plan
  • Alexander
    Alexander over 5 years
    Can you do ls -la in this folder and post the results here? Also try pwd to list the current directory.
  • Arpan
    Arpan over 5 years
    Looks like there was some issue with the vpn connectivity and was not able to connect to aws system .. it is working now after making some changes.
  • Eric Aya
    Eric Aya over 2 years
    This is the same solution as in this other answer.
  • Br.Bill
    Br.Bill over 2 years
    But what if you ARE in the folder and you still get this message?