In the previous tutorial, you created a workspace and connected it to your GitHub repository.
In this tutorial, you will learn how to retrieve your AWS credentials and set your Terraform Cloud variables to use those values. From there, you will queue and apply your configuration to provision a DynamoDB.
The example repository uses the Amazon Web Services (AWS) provider. In order to use it, you will need an AWS account. If you don't have an AWS account already, create one now.
This example is intended to only create resources which qualify under the AWS free tier.
Warning! If you're not using an account that qualifies under the AWS free tier, you may be charged to run these examples. The most you should be charged should only be a few dollars, but we're not responsible for any charges that may incur.
Once you have an AWS account, you'll need user credentials so that Terraform can use your AWS account to apply the example configuration.
You can follow the AWS
to create a user with Programmatic access and Administrator permissions,
either through membership in an IAM Group with the
or by attaching the
AdministratorAccess policy directly.
Warning! While Terraform Cloud stores your credentials and other variables securely, we recommend disabling or deleting the user you create for this tutorial after you are done. Always follow security best practices when managing credentials.
When you create the user, you will receive an Access key ID and a Secret access key. Be sure to keep these values in a secure location; you will use them in the next step.
»Configure workspace variables
Now that you have your AWS Access key ID and Secret access key, return to the Terraform Cloud UI. Within your new workspace, visit the "Variables" page.
Terraform Cloud supports both Terraform Variables and Environment Variables. We'll use both types in this tutorial.
Scroll down to the "Environment Variables" section, and create two variables.
AWS_ACCESS_KEY_IDwith the Access key ID from the prior step
AWS_SECRET_ACCESS_KEYwith the Secret access key
Check the "Sensitive" checkbox for both of these variables and click the "Save variable" button to save each one. Once you are done, the "Environment Variables" section should look like this.
Just like when running Terraform on your local machine, Terraform Cloud will load these environment variables when planning and applying changes to your configuration.
Note: If you have been using the Terraform CLI, be aware that your local environment variables do not carry over to Terraform Cloud. This step configures Terraform Cloud to run AWS actions on your behalf by providing your credentials.
We also included two Terraform Variables in the example configuration. Scroll up to the "Terraform Variables" section to set those up now.
When you are done, the "Terraform Variables" section should look like this.
»Queue and apply plan
Now that your workspace is configured, use the "Queue Plan" button to start a plan. You may give a reason in the provided text box. Terraform Cloud will run a plan step, which creates a list of the requested changes. This may take a few minutes.
Once the plan is complete, you need to confirm it before you can apply it.
Click the "Confirm & Apply" button to continue. You can include a comment if you like.
After a few minutes, your plan should be applied successfully and you can see the results in Terraform Cloud.
The provided example configuration provisions an AWS DynamoDB table. You can optionally visit the AWS web console to verify that Terraform provisioned the table. The configuration defaults to using the N. California/us-west-1 region, so be sure to look for the DynamoDB table in that region.
There have been several steps involved in getting to this point, so it is
possible that an error occurred due to a missed step, a typo, or another
problem. If an error does occur during the
apply step, Terraform
Cloud will display the error message on the "Run" page to help you troubleshoot
Note 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 and provisioned a DynamoDB instance using Terraform Cloud.
In the next tutorial, you will modify your DynamoDB instance by updating your Terraform variables and changing your configuration files.