variable "aws_access_key" {
type = string
description = "AWS Access Key"
sensitive = true
}
variable "aws_secret_key" {
type = string
description = "AWS Secret Key"
sensitive = true
}
variable "project" {
type = string
description = "Project name for resource tagging"
}
variable "billing_code" {
type = string
description = "Billing code for resource tagging"
}
All the variable need a supplied values. If we want to submit values for all of these variables at the command line, use this command.
terraform plan -var=billing_code="ACIT123" -var=project="web-app" -var=aws_access_key="ACCESS_KEY" -var=aws_secret_key="SECRET_KEY" -out m4.tfplan
Let’s create a file called terraform.tfvars and populate it with some of our non-sensitive variables and values.
billing_code = "ACIT123"
project = "web-app"
We can store our sensitive data in environment variables like this:
# For Linux and MaxOS
export TF_VAR_aws_access_key=YOUR_ACCESS_KEY
export TF_VAR_aws_secret_key=YOUR_SECRET_KEY
# For PowerShell
$env:TF_VAR_aws_access_key="YOUR_ACCESS_KEY"
$env:TF_VAR_aws_secret_key="YOUR_SECRET_KEY"
terraform plan -out m4.tfplan
terraform apply "m4.tfplan"