You now have a Terraform Cloud workspace connected to a version control repository and configured to use AWS credentals defined in a Terraform Cloud variable set. You can further configure your workspace using workspace-specific variables.
In this tutorial, you will customize the workspace you created earlier in this collection by defining Terraform variables for your EC2 settings. You will then use Terraform Cloud to provision your EC2 instance.
»Configure Terraform variables
Both workspace-specific variables and reusable variable sets support Terraform variables and environment variables. 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.
Return to the Terraform Cloud UI and navigate to the Variables page for
tfc-guide-example workspace. Find the Workspace variables section to
set two variables that Terraform will use to configure your instance. Then,
click + Add variable.
First, define a Terraform variable by selecting the Terraform variable
radio button. Set the key to
instance_type and value to
Click Save variable.
Then, click + Add variable again. Create another Terraform variable
with the key
instance_name and the value
Provisioned by Terraform. Click Save variable.
Your workspace is now configured with 2 workspace-specific input variables and
AWS Credentials variable set as configured in the previous tutorial.
»Plan infrastructure changes
Now that you have set your Terraform variables, select Start new plan from the Actions drop down menu.
Choose the Plan (most common) option, and provide an optional explanation. Then select the purple Start plan button to start a plan. This may take a few minutes.
This produces an execution plan that describes which actions Terraform will take to change real infrastructure to match the configuration. Terraform will not make any changes until you confirm and apply the plan. This gives you and your team an opportunity to review the planned changes.
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, click the Confirm & Apply button, followed by the Confirm Plan button to apply the change.
After a few minutes, your apply should complete. Terraform Cloud will display a confirmation.
Now return to the workspace's Overview page. Under the details about your latest run, Terraform displays a table of the resources currently managed in the workspace.
It also shows the workspace's outputs in the Outputs tab for easy access.
Congratulations! You created an AWS EC2 instance using Terraform Cloud. Verify that the infrastructure exists by visiting the AWS web console page for EC2 in the N. California/us-west-1 region, the region specified in the provider configuration.
Tip: The EC2 instance 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 workspace-specific Terraform variables, and created a EC2 instance using Terraform Cloud. Read more about variables in Terraform Cloud in the documentation.
Now you are ready to modify your EC2 instance by updating your Terraform variables and changing your configuration files.