Create a workspace
Once you have created a Terraform Cloud account and created or joined an organization, you can start managing infrastructure with Terraform Cloud. In this tutorial, you will create a CLI-driven workspace.
Prerequisites
While Terraform can provision resources on many different providers and connect with several popular version control systems (VCSs), this tutorial requires:
- a Terraform Cloud account and organization
- Terraform v1.1+ installed locally and configured with your Terraform Cloud token
- an AWS account
- a GitHub account
Clone a Github repository
Clone the example GitHub repository for this tutorial, which contains the Terraform configuration that defines an AWS EC2 instance and its attributes.
Change to the repository directory.
Open the configuration in your code editor to review it. It contains Terraform configuration files, which define and expose information about your infrastructure:
main.tf
specifies the AWS provider, a provider plugin that Terraform will use to manage your AWS resources. The configuration defines an EC2 instance and uses a Terraform data source to access a machine image to use for the instance.variables.tf
defines the input variables that are referenced inmain.tf
, which make the configuration customizable. You will define these variables in the Terraform Cloud UI later on in this tutorial.outputs.tf
defines the information about your infrastructure that Terraform Cloud will display to you when it makes changes.terraform.tf
defines version constraints for Terraform and the AWS provider and thecloud
block for the Terraform Cloud integration.
Update configuration
Open the terraform.tf
file and update the name of the organization
in the
cloud
block to your own Terraform Cloud organization. You can find your
organization name in the breadcrumbs of the Terraform Cloud UI.
Create the workspace
This cloud
block specifies which Terraform Cloud organization and workspace
to use for the operations in this working directory. When using the CLI-driven
Terraform Cloud workflow, running terraform init
on configuration with a
cloud
block creates the Terraform Cloud workspace specified in the block, if it does not
already exist.
In your terminal, run terraform init
to initialize the configuration and create your new Terraform Cloud workspace.
Tip
Make sure that you have authenticated with Terraform Cloud using the terraform login
command prior to running this step.
As part of the initialization process, Terraform created the new learn-terraform-cloud
workspace in your Terraform Cloud organization, configured for CLI-driven runs.
Every Terraform Cloud workspace belongs to a project, which is a group of workspaces. When you create your workspace using this automated CLI workflow, Terraform Cloud adds the workspace to your organization's Default project. Projects help you organize your workspaces into groups, making it easier to find workspaces in large Terraform Cloud organizations.
Assign variable set to workspace
If you are not using a global variable set with your AWS credentials in your Terraform Cloud organization, assign the variable set to your new workspace.
Navigate to your new learn-terraform-cloud
workspace. Select Variables in
the workspace's menu. Under Variable sets, click Apply variable
set.
Select your AWS Credentials
variable set, then click Apply variable set.
Your workspace can now use your AWS credentials. If you update the values of the variables in the variable set, those changes will propagate to this workspace and apply to all future runs.
Next Steps
In this tutorial, you updated a cloud
block for your own Terraform Cloud organization, created a CLI-driven Terraform Cloud workspace, and configured it with a variable set.
Next, you will review, configure, and use your new workspace.