I am attempting to use an environment variable in my terraform main.tf file. I ran the following command in my development environment:
TF_VAR_source_ami=ami-048e57a7474e7284d
echo $TF_VAR_source_ami
ami-048e57a7474e7284d
Here are the contents for main.tf:
variable "source_ami" {
type = "string"
description = "AMI to copy this account"
}
data "aws_ami" "ami_to_be_shared" {
owners = ["self"]
most_recent = true
filter {
name = "image-id"
values = ["${var.source_ami}"]
}
}
output "ami_creation_date" {
value = "${data.aws_ami.ami_to_be_shared.tags.AMICoreEngDate}"
}
When I run terraform plan
, it prompts me for var.source_ami
however, when I run terraform apply -var="source_ami=ami-048
e57a7474e7284d"
it works.
I have also tried declaring the variable without a type and description.
Additional information:
- using AWS Cloud9
- terraform version Terraform v0.11.5
- following this documentation: https://www.terraform.io/docs/configuration-0-11/variables.html
- Also read the post: Can Terraform use bash environment variables?
Thank you for any help!