s3.tf
terraform {
backend "s3" {
bucket = "some-bucket"
key = "path/to/key"
region = "some-aws-region"
}}
How to pass the bucket and region values to this from a variables.tf file?
Provide the S3 bucket name and DynamoDB table name to Terraform within the S3 backend configuration using the bucket and dynamodb_table arguments respectively, and configure a suitable workspace_key_prefix to contain the states of the various workspaces that will subsequently be created for this configuration.
In many cases it is desirable to apply more precise access constraints to the Terraform state objects in S3, so that for example only trusted administrators are allowed to modify the production state, or to control reading of a state that contains sensitive information.
If you want to dynamically configure the backend you need to write a wrapper script or provide a backend-config via the arguments terraform.io/docs/language/settings/backends/… terragrunt is a nice project that's essentially a wrapper to terraform configurations.
What this section of code does is it tells Terraform that we want to use an S3 backend instead of our local system to manage our state file. The rest of the code block simply references some of the different resources that we created earlier. Once again, we are required to run terraform init because we’re changing the management of the state file.
hello here's a solution :
terraform {
backend "s3" {
}
}
pass the backend like that and then :
on the terraform init command :
terraform init \
-backend-config="bucket=${TFSTATE_BUCKET}" \
-backend-config="key=${TFSTATE_KEY}" \
-backend-config="region=${TFSTATE_REGION}"
you should use env to set TFSTATE_BUCKET TFSTATE_KEY and TFSTATE_REGION
here's a link of the docs : the Terraform docs on "Partial Configuration" of Backends
I believe this is not currently possible as if you add a variable interpolation in that, you will get an error
terraform.backend: configuration cannot contain interpolations
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With