Mystic
Mystic

Reputation: 1030

Add an `aws_acm_certificate` resource to a terraform file causes terraform to ignore vars

Using the aws_acm_certificate resources makes terraform ignore provided variables.

Here's a simple terraform file:

variable "aws_access_key_id" {}
variable "aws_secret_key" {}
variable "region" { default = "us-west-1" }

provider "aws" {
  alias = "prod"

  region = "${var.region}"
  access_key = "${var.aws_access_key_id}"
  secret_key = "${var.aws_secret_key}"
}

resource "aws_acm_certificate" "cert" {
  domain_name       = "foo.example.com"
  validation_method = "DNS"

  tags {
    project = "foo"
  }

  lifecycle {
    create_before_destroy = true
  }

}

Running validate, plan, or apply fails:

$ terraform validate -var-file=my.tfvars 
$ cat my.tfvars
region = "us-west-2"
aws_secret_key = "secret"
aws_access_key_id = "not as secret"

Upvotes: 0

Views: 178

Answers (1)

BMW
BMW

Reputation: 45323

There is nothing wrong in your codes.

Please do some cleans and run again (only run the rm command when you fully understand what you are doing)

rm -rf .terraform
rm terraform.tfstate*

terraform fmt
terraform get -update=true
terraform init
terraform plan

Upvotes: 0

Related Questions