Skip to main content

Create Terraform Cloud Workspace

Next you'll create a Terraform Cloud workspace, which is how Terraform Cloud manages collections of infrastructure resources. You can use the Terraform CLI to create this new workspace.

First, clone the example GitHub repository for this tutorial, which includes the Terraform configuration files for the Fake Web Services provider and connection to Terraform Cloud. The Terraform Fake Web Services provider allows you to create and manage infrastructure resources in the same manner as you would manage cloud resources via Terraform for AWS, GCP, or Azure without creating actual cloud resources or interacting with a cloud provider.

To start, in your terminal run:

git clone https://github.com/StyraInc/tfc-das-tutorial.git

Then change to the cloned repository's directory:

cd tfc-das-tutorial

Open the terraform.tf file in your preferred code editor, update the organization value in the cloud block to the your Terraform Cloud organization name, and save your changes.

In your terminal, run terraform init to create the Terraform Cloud workspace and install the Fake Web Services provider.

Figure 1 - Initialize Terraform

Once the command finishes running, you can go to Terraform Cloud to see your new workspace:

Figure 2 - Workspace in Terraform Cloud

Set Provider Token

Similar to how a cloud provider configuration requires a token to interact with the provider, the Fake Web Services provider requires a Terraform Cloud user API token. For details about user API tokens and how to generate one, refer to Terraform Cloud's User API Tokens documentation.

Next, you will need to add a variable for your Terraform Cloud workspace with the token value. Following the steps in Terraform Cloud's Workspace-Specific Variables documentation, add a Workspace environment variable with a key of TF_VAR_PROVIDER_TOKEN and the value set to the generated user API token from above. Ensure you check the Sensitive checkbox to protect the token value, then click Save variable.

Figure 3 - Add Workspace Variable

Create Your First Infrastructure Resource

The example repo for this tutorial includes a VPC resource definition for the Fake Web Services provider with a CIDR block of 10.1.0.0/16 in the main.tf file:

resource "fakewebservices_vpc" "primary_vpc" {
name = "Primary VPC"
cidr_block = "10.1.0.0/16"
}

In your terminal, run terraform apply and confirm the plan by typing yes. Terraform will now create the defined fake VPC resource.