Terraform
Last updated
Was this helpful?
Last updated
Was this helpful?
This walkthrough shows you how to pass CloudTruth parameters as Environment Variables to Terraform.
You can also use CloudTruth to externally reference backend .
You know basic .
You have created a and installed the .
For this example we will build on top of the to deploy an EC2 instance defining variables with CloudTruth parameters. You can use any target for your deploys.
Create a CloudTruth Project called Terraform
.
Now you can create the CloudTruth parameters in the Terraform project that we will pass to Terraform as with the TF_VAR_
convention.
ami
string
ami-830c94e3
instance_type
string
t2.micro
availability_zone_names
list
["us-west-2a", "us-west-2b"]
resource_tags
map
{"Name":"Cloudtruth-Instance","project":"CloudTruth Run Terraform","environment":"default"}
Now when executing a terraform plan
you will notice that you are prompted to enter values for each variable defined.
CloudTruth Run
The following command will pass the variables from the Terraform
project where we set our input variables directly into terraform apply
.
Terraform will show the outputs and deploy the instance with our CloudTruth values.
Couple this method with CloudTruth Environments and you can manage and deploy different instance types with various configuration setting to your Prod, Dev and Staging with a single command.
Terraform Input Variables
From your update your main.tf
with the following configuration.
This main.tf will deploy an EC2 instance to us-west-2 and that are centrally managed by CloudTruth. It also shows you how to use various Terraform variable such as a and .
From your Terraform working directory .
You can manage your Terraform configuration centrally with CloudTruth and pass Terraform with the cloudtruth run CLI command.
CloudTruth run injects environment variables into your terraform commands. Terraform searches the environment for variables that contain preceding the variable name defined in your configuration script. The variable is case sensitive so if it is lower case in main.tf
the variables must have lower case key names in CloudTruth.
Environment input variables have a specific and CloudTruth run can be used with any combination that Terraform allows. Values from CloudTruth run be overridden by a file if the same variable exists in a terraform.tfvars
or any of the higher precedence methods of passing values.