Terraform provider/variable sharing in modules

Right now it’s not possible to achieve that. There were previous discussions on github about the same topic in the following issues: https://github.com/hashicorp/terraform/issues/5480 https://github.com/hashicorp/terraform/issues/4585 https://github.com/hashicorp/terraform/issues/2714 https://github.com/hashicorp/terraform/issues/1742 https://github.com/hashicorp/terraform/issues/1478 TL;DR the sharing of variables between modules is against terraform core clarity/explicity principles. Workaround A workaround is to have the *shared* files in the parent directory and using … Read more

Error refreshing state: state data in S3 does not have the expected content [closed]

There are 3 possible workarounds depending on your specific scenario in order to solve it: Case 1 If you have a backup of your AWS S3 terrform.tfstate file you could restored your state backend “s3” {key = “path/to/terraform.tfstate”} to an older version. Re try terraform init and validate if it works well. Case 2 Remove … Read more

How to write an if, else, elsif conditional statement in Terraform

This is one way using the coalesce() function: locals{ prod = “${var.environment == “PROD” ? “east” : “”}” prod2 = “${var.environment == “PROD2” ? “west2” : “”}” nonprod = “${var.environment != “PROD” && var.environment != “PROD2” ? “west” : “”}” region = “${coalesce(local.prod,local.prod2, local.nonprod)}” }

Conditional attributes in Terraform

Terraform 0.12 (yet to be released) will also bring support for HCL2 which allows you to use nullable arguments with something like this: resource “aws_ebs_volume” “my_volume” { availability_zone = “xyz” size = 30 snapshot_id = var.staging_mode ? local.a_specific_snapshot_id : null } Nullable arguments are covered in this 0.12 preview guide. For version of Terraform before … Read more