DEV Community

leroykayanda
leroykayanda

Posted on • Edited on

2 2

Initial set up for Terraform Cloud

Install and manage terraform using tfenv

Some terraform projects need older terraform versions and would break if upgraded to newer versions. Tfenv helps manage multiple local terraform versions.

Uninstall terraform if already installed. It causes conflicts with tfenv.

brew uninstall terraform

Install tfenv

brew install tfenv

List available terraform versions.

tfenv list-remote
1.10.0-alpha20240730
1.10.0-alpha20240717
1.10.0-alpha20240619
1.10.0-alpha20240606
1.9.3
1.9.2
1.9.1
1.9.0
1.9.0-rc3
Enter fullscreen mode Exit fullscreen mode

Install the latest available version.

tfenv install latest

Alternatively install a particular version

tfenv install 1.9.2

List the installed versions.

tfenv list
* 1.9.3 (set by /opt/homebrew/Cellar/tfenv/3.0.0/version)
  1.9.2
Enter fullscreen mode Exit fullscreen mode

Confirm terraform cmd works.

terraform -v
Terraform v1.9.3
Enter fullscreen mode Exit fullscreen mode

Change the default terraform version.

tfenv use 1.9.2 
 Switching default version to v1.9.2 
 Default version (when not overridden by .terraform-version or TFENV_TERRAFORM_VERSION) is now: 1.9.2 

terraform -v 
 Terraform v1.9.2 
Enter fullscreen mode Exit fullscreen mode

Switch to the latest available version.

tfenv use latest

terraform -v
Terraform v1.9.3
Enter fullscreen mode Exit fullscreen mode

Install this vscode extension.

extension

Open a terraform cloud account. Create a workspace with a VCS workflow.

Set up dynamic AWS credentials using OIDC.

Set up a simple script to launch an EC2 instance.

https://github.com/hashicorp/tfc-guide-example

Use this in the terraform block.

terraform {

  backend "remote" {
    hostname     = "app.terraform.io"
    organization = "org-name"

    workspaces {
      name = "workspace_name"
    }
  }

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 4.4.0"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Log in to terraform cloud terraform login

Run terraform init

Trigger an apply by running terraform apply.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay