Movatterモバイル変換


[0]ホーム

URL:


HashiConf 2025Don't miss the live stream of HashiConf Day 2 happening now View live stream

Organize workspaces with projects and variable sets

  • 5min
  • |
  • HCP Terraform
  • Terraform
  • Video

In the previous tutorial, you created a workspace and assigned variable values so that your Terraform runs can authenticate to your cloud provider. As your infrastructure operations scale, you may need to use multiple workspaces to effectively manage your resources.

Projects let you organize your workspaces into groups so that you can manage their access, variables, and settings collectively. To manage variables across workspaces in bulk, you can create variable sets and assign them to your projects. When you update a variable in a set, the change propagates to every workspace and project you assigned the variable set to.

In this tutorial, you will create a project and move your workspace into it. Then, you will create a new variable set and assign it to the new project.

Prerequisites

To follow this tutorial, you will need:

Create new project

Log in to HCP Terraform, then clickProjects in the left navigation panel. This page lists all of the projects in your organization. If you recently created this organization, you may only see one project namedDefault Project.

To create a new project, click theNew project button in the top-right corner. Name the projectLearn Terraform, then clickCreate.

After you create your project, HCP Terraform shows you the project overview page. From this page, you can see which workspaces are in the project and access the project's settings.

Create variable set

Next you will create a new variable set and assign it to the project.

From your project overview page, clickSettings, then clickVariable sets. ClickCreate project variable set to create a new project-scoped variable set.

Tip

In this tutorial, you create a project-scoped variable set. You can also create variable sets that apply to every project and workspace in the organization. Refer to thecreate variable sets documentation for more information.

Name the variable setlearn-aws. UnderVariable set scope, chooseApply to the entire project. Then, underVariables, create two new variables.

CategoryKeyValueSensitive
EnvironmentAWS_ACCESS_KEY_IDYour AWS secret IDDisabled
EnvironmentAWS_SECRET_ACCESS_KEYYour AWS secret keyEnabled

After you create both variables, clickCreate variable set. Because you assigned this variable set to the entire project, every workspace in the project will automatically access these two environment variables, allowing your workspaces to authenticate to AWS.

Move workspace to new project

Next, move your workspace to the new project. Return to your organization overview page, clickWorkspaces, then choose yourlearn-hcp-terraform workspace.

From your workspace overview page, clickSettings in the left navigation panel, click the drop-down underProject, and choose yourLearn Terraform project. Scroll to the bottom of the page and clickSave settings.

HCP Terraform applies the variable values according to precedence. Your workspace inherits the variables you defined in your project's variable set, but workspace variables override variables in a project variable set.

Because you no longer need to define your AWS credentials as workspace variables, remove them from your workspace. Click thelearn-hcp-terraform link in the top-left to return to your workspace overview, then clickVariables.

Open the ellipses menu (...) for theAWS_ACCESS_KEY_ID variable, then clickDelete. Confirm that you want to delete this variable when prompted. Repeat this process for theAWS_SECRET_ACCESS_KEY variable.

Verify that your workspace uses the project's variable set by starting a new plan-only run. In the top-right corner, clickNew run, click the drop-down underRun type, then choosePlan only. ClickStart to begin the new run.

Ensure that the plan-only operation completes successfully. Though you did not update your configuration, Terraform still needs to authenticate with AWS to gather information about your virtual machine. This validates that your workspace now uses the project's variable set to set the AWS environment variables.

Next steps

In this tutorial, you created a new project to organize workspaces, then you created a new variable set with your AWS credentials. You assigned this variable set to the project, so that every workspace in the project has access to the credentials. You also moved your workspace to the new project and deleted the workspace-specific variables to verify that it uses the project's variable set.

By organizing your workspaces into projects and using variable sets, you can enable infrastructure operations in new workspaces without needing to manage variables and credentials in each individual workspace.

Continue to the next tutorial to learn how to link workspaces together, share outputs, and trigger runs in one workspace from another.

This tutorial also appears in:

  • 35 tutorials
    Collaborate using HCP Terraform
    Collaborate on infrastructure with HCP Terraform. Follow these tutorials to migrate state from local storage and take a deeper look at HCP Terraform operations, including VCS integration, workspace configuration, and remote runs.
    • Terraform

[8]ページ先頭

©2009-2025 Movatter.jp