Once you have created a workspace and connected it to a version control repository, you are ready to configure the workspace with environment and Terraform input variables. You can then create your infrastructure.
In this tutorial, you will customize your DynamoDB settings as Terraform variables. Then you will retrieve your AWS credentials and set them as sensitive environment variables. Finally, you will provision a DynamoDB table with Terraform Cloud.
»Configure Terraform variables
Return to the Terraform Cloud UI and visit the "Variables" page, where you will set your credentials.
Terraform Cloud supports two types of variables: environment variables and Terraform variables. Either type can be marked as sensitive, which prevents them from being displayed in the Terraform Cloud web UI and makes them write-only.
Terraform Cloud will define Terraform Variables as input variables in Terraform's configuration language. You can use them to customize the infrastructure that Terraform creates from your configuration.
Find the "Terraform Variables" section to set two variables that Terraform will use to configure your DynamoDB table.
Click the "Save variable" button to save each one. When you are done, the "Terraform Variables" section should look like this.
»Find your AWS credentials
DynamoDB tables are an Amazon Web Services (AWS) service. In order for Terraform to provision AWS resources for you, it needs credentials for your AWS account.
Note: This tutorial will provision resources that qualify under the AWS free-tier. If your account doesn't qualify under the AWS free-tier, we're not responsible for any charges that you may incur.
Log into the AWS console and find your Access key ID and Secret access key on this page.
»Configure environment variables
Terraform Cloud creates an ephemeral VM to run Terraform operations (which create and manage your infrastructure). You will set that VM's Environment Variables in the Terraform Cloud web UI to configure provider credentials or to configure the Terraform binary itself.
Scroll down to the Environment Variables section, and create two variables by clicking the "Add variable" button. Check the "Sensitive" checkbox for both of them.
|Your AWS Access key ID||yes|
|Your AWS Secret access key||yes|
Click the "Save variable" button to save each one. Once you are done, the "Environment Variables" section should look like this.
Tip: If you use the Terraform CLI, your local environment variables do not auto populate into the VM where Terraform Cloud runs the Terraform binary. You must set your environment variables in Terraform Cloud.
»Plan infrastructure changes
Now that you've set your variables, click the "Queue plan" menu button and provide an optional explanation. Then click the purple "Queue plan" button to start a plan. This may take a few minutes.
This output shows the execution plan, describing which actions Terraform will take in order to change real infrastructure to match the configuration.
The output format is similar to the diff format generated by tools such as Git. Output with a
+ next to it means that Terraform will create this resource. The plan also shows the attributes that Terraform will set. The value
(known after apply) means that Terraform will not have this value until after it creates the resource.
No real infrastructure changes happen until you confirm and apply the plan. This checkpoint gives you and your team an opportunity to review the planned changes before they happen.
»Apply planned changes
Once the plan is complete, accept the changes by clicking the "Confirm & Apply" button and include an optional comment if you like.
After a few minutes, your apply should complete. Terraform Cloud will display a confirmation.
Congratulations; you created an AWS DynamoDB table using Terraform Cloud. Verify that the infrastructure exists by visiting the AWS web console page for DynamoDB in the N. California/us-west-1 region, where the configuration specified that the table should be located.
Tip: The DynamoDB table that you have provisioned will remain active until it is deleted. You will do this in the clean-up tutorial.
In this tutorial, you configured your workspace with environment and Terraform variables, and created a DynamoDB table using Terraform Cloud. Read more about variables in Terraform Cloud in the documentation.
Now you are ready to modify your DynamoDB table by updating your Terraform variables and changing your configuration files.