Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to show current state version Outputs #732

Merged
merged 7 commits into from
Feb 19, 2024
Merged

Conversation

alfespa17
Copy link
Member

@alfespa17 alfespa17 commented Feb 19, 2024

Add support for endpoint

GET /workspaces/:workspace_id/current-state-version-outputs

Example Terraform 1.5.7:

user@pop-os:~/git/simple-terraform$ terraform init

Initializing Terraform Cloud...
Initializing modules...
- time_module in module

Initializing provider plugins...
- Finding latest version of hashicorp/random...
- Finding latest version of hashicorp/null...
- Finding latest version of hashicorp/time...
- Installing hashicorp/random v3.6.0...
- Installed hashicorp/random v3.6.0 (signed by HashiCorp)
- Installing hashicorp/null v3.2.2...
- Installed hashicorp/null v3.2.2 (signed by HashiCorp)
- Installing hashicorp/time v0.10.0...
- Installed hashicorp/time v0.10.0 (signed by HashiCorp)

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

Terraform Cloud has been successfully initialized!

You may now begin working with Terraform Cloud. Try running "terraform plan" to
see any changes that are required for your infrastructure.

If you ever set or change modules or Terraform Settings, run "terraform init"
again to reinitialize your working directory.

user@pop-os:~/git/simple-terraform$ terraform apply

Terraform used the selected providers to generate the following execution plan.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # null_resource.next will be created
  + resource "null_resource" "next" {
      + id = (known after apply)
    }

  # null_resource.next2 will be created
  + resource "null_resource" "next2" {
      + id = (known after apply)
    }

  # null_resource.next3 will be created
  + resource "null_resource" "next3" {
      + id = (known after apply)
    }

  # null_resource.previous will be created
  + resource "null_resource" "previous" {
      + id = (known after apply)
    }

  # time_sleep.wait_30_seconds will be created
  + resource "time_sleep" "wait_30_seconds" {
      + create_duration = (known after apply)
      + id              = (known after apply)
    }

  # module.time_module.random_integer.time will be created
  + resource "random_integer" "time" {
      + id     = (known after apply)
      + max    = 5
      + min    = 1
      + result = (known after apply)
    }

Plan: 6 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + creation_time = (known after apply)

Do you want to perform these actions in workspace "simple"?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

module.time_module.random_integer.time: Creating...
null_resource.previous: Creating...
module.time_module.random_integer.time: Creation complete after 0s [id=1]
null_resource.previous: Creation complete after 0s [id=8606013738117450615]
time_sleep.wait_30_seconds: Creating...
time_sleep.wait_30_seconds: Creation complete after 1s [id=2024-02-19T22:12:22Z]
null_resource.next: Creating...
null_resource.next3: Creating...
null_resource.next2: Creating...
null_resource.next: Creation complete after 0s [id=543896380271504777]
null_resource.next2: Creation complete after 0s [id=1648997494072671356]
null_resource.next3: Creation complete after 0s [id=7331222573589835622]

Apply complete! Resources: 6 added, 0 changed, 0 destroyed.

Outputs:

creation_time = "1s"



user@pop-os:~/git/simple-terraform$ terraform output
creation_time = "1s"

Example tofu 1.6.1:

user@pop-os:~/git/simple-terraform$ tofu init

Initializing cloud backend...
Initializing modules...
- time_module in module

Initializing provider plugins...
- Finding latest version of hashicorp/null...
- Finding latest version of hashicorp/time...
- Finding latest version of hashicorp/random...
- Installing hashicorp/time v0.10.0...
- Installed hashicorp/time v0.10.0 (signed, key ID 0C0AF313E5FD9F80)
- Installing hashicorp/random v3.6.0...
- Installed hashicorp/random v3.6.0 (signed, key ID 0C0AF313E5FD9F80)
- Installing hashicorp/null v3.2.2...
- Installed hashicorp/null v3.2.2 (signed, key ID 0C0AF313E5FD9F80)

Providers are signed by their developers.
If youd like to know more about provider signing, you can read about it here:
https://opentofu.org/docs/cli/plugins/signing/

OpenTofu has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that OpenTofu can guarantee to make the same selections by default when
you run "tofu init" in the future.

Cloud backend has been successfully initialized!

You may now begin working with cloud backend. Try running "tofu plan" to
see any changes that are required for your infrastructure.

If you ever set or change modules or OpenTofu Settings, run "tofu init"
again to reinitialize your working directory.



user@pop-os:~/git/simple-terraform$ tofu output
creation_time = "4s"
fake_data = {
  "data" = "Hello World"
  "resource" = {
    "resource1" = "fake"
  }
}




user@pop-os:~/git/simple-terraform$ tofu output -json
{
  "creation_time": {
    "sensitive": false,
    "type": "string",
    "value": "4s"
  },
  "fake_data": {
    "sensitive": false,
    "type": [
      "object",
      {
        "data": "string",
        "resource": [
          "object",
          {
            "resource1": "string"
          }
        ]
      }
    ],
    "value": {
      "data": "Hello World",
      "resource": {
        "resource1": "fake"
      }
    }
  }
}

Fix #701

Copy link

@alfespa17 alfespa17 merged commit 403c689 into main Feb 19, 2024
4 checks passed
@jcanizalez jcanizalez deleted the handle-outputs branch February 20, 2024 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tofu outputs does not work with Terrakube's "cloud" backend
1 participant