Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform required_version prevents s3 remote backend initialization #12905

Closed
gevgev opened this issue Mar 21, 2017 · 2 comments · Fixed by #12942
Closed

terraform required_version prevents s3 remote backend initialization #12905

gevgev opened this issue Mar 21, 2017 · 2 comments · Fixed by #12942
Assignees

Comments

@gevgev
Copy link

gevgev commented Mar 21, 2017

we have the following files in the folder:

backend.tf 
main.tf
vars.tf

The content for the backend.tf:

terraform {
    backend "s3" {
        bucket 		= "BUCKET_NAME"
        key 		= "KEY_PATH/s3.json"
        region 		= "us-east-1"

        lock 		= "true"
        encrypt		= "true"
        lock_table 	= "terraform_state_lock"
        acl		= "bucket-owner-full-control"
    }
}

The content for the main.tf (can be anything - important is the terraform required_version):

terraform {
  required_version = ">= 0.9.1"
}

resource "aws_s3_bucket" "terraform_state" {
  bucket = "${var.bucket_name}"

  versioning {
    enabled = true
  }

  lifecycle {
    prevent_destroy = true
  }
}

With these files above terraform init -backend=true still initializes to local state:

$ ./terraform init -backend=true /PATH_TO_PROJECT/s3
Initializing configuration from: "/PATH_TO_PROJECT/s3"...

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your environment. If you forget, other
commands will detect it and remind you to do so if necessary.

If we remove terraform required_version from main.tf, then we get the project backend properly configured to s3.

main.tf content (no terraform required_version):

resource "aws_s3_bucket" "terraform_state" {
  bucket = "${var.bucket_name}"

  versioning {
    enabled = true
  }

  lifecycle {
    prevent_destroy = true
  }
}

Execution output:

./terraform init -backend=true /PATH_TO_PROJECT/s3
Initializing configuration from: "PATH_TO_PROJECT/s3"...
Initializing the backend...


Successfully configured the backend "s3"! Terraform will automatically
use this backend unless the backend configuration changes.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your environment. If you forget, other
commands will detect it and remind you to do so if necessary.
@mitchellh
Copy link
Contributor

Notes: this is a bug in Terraform merge logic in config/append.go

@jbardin jbardin self-assigned this Mar 21, 2017
jbardin added a commit that referenced this issue Mar 22, 2017
merge config.Terraform fields in config.Append
@ghost
Copy link

ghost commented Apr 15, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants