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

Terraform 1.6.X support #557

Merged
merged 8 commits into from
Oct 26, 2023
Merged

Terraform 1.6.X support #557

merged 8 commits into from
Oct 26, 2023

Conversation

alfespa17
Copy link
Member

Adding support to use Terraform 1.6.X with remote and local execution.

Terraform Files.

Test is using the following code:

terraform {
  cloud {
    organization = "simple"
    hostname = "8080-azbuilder-terrakube-kol6dwnt5ol.ws-us105.gitpod.io"

    workspaces {
      tags = ["test1"]
    }
  }
}

# This resource will destroy (potentially immediately) after null_resource.next
resource "null_resource" "previous" {}

resource "time_sleep" "wait_5_seconds" {
  depends_on = [null_resource.previous]

  create_duration = "5s"
}

# This resource will create (at least) 30 seconds after null_resource.previous
resource "null_resource" "next" {
  depends_on = [time_sleep.wait_5_seconds]
}

resource "time_sleep" "wait_50_seconds" {
  depends_on = [null_resource.previous]

  create_duration = "5s"
}

output "creation_time" {
    value = time_sleep.wait_5_seconds.create_duration
}

Terraform 1.6.2 (remote)

user@pop-os:~/git/terraform-modules/shared-workspace/workspace1$ terraform -version
Terraform v1.6.2
on linux_amd64
+ provider registry.terraform.io/hashicorp/null v3.2.1
+ provider registry.terraform.io/hashicorp/time v0.9.1
user@pop-os:~/git/terraform-modules/shared-workspace/workspace1$ terraform init

Initializing Terraform Cloud...

No workspaces found.
  
  There are no workspaces with the configured tags (test1)
  in your Terraform Cloud organization. To finish initializing, Terraform needs at
  least one workspace available.
  
  Terraform can create a properly tagged workspace for you now. Please enter a
  name to create a new Terraform Cloud workspace.

  Enter a value: test1-remote


Initializing provider plugins...
- Finding latest version of hashicorp/null...
- Finding latest version of hashicorp/time...
- Installing hashicorp/null v3.2.1...
- Installed hashicorp/null v3.2.1 (signed by HashiCorp)
- Installing hashicorp/time v0.9.1...
- Installed hashicorp/time v0.9.1 (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/terraform-modules/shared-workspace/workspace1$ terraform apply

Running apply in Terraform Cloud. Output will stream here. Pressing Ctrl-C
will cancel the remote apply if it's still pending. If the apply started it
will stop streaming the logs, but will not stop the apply running remotely.

Preparing the remote apply...

To view this run in a browser, visit:
https://8080-azbuilder-terrakube-kol6dwnt5ol.ws-us105.gitpod.io/app/simple/test1-remote/runs/1

Waiting for the plan to start...

***************************************
Running Terraform PLAN
***************************************

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.previous will be created
  + resource "null_resource" "previous" {
      + id = (known after apply)
    }

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

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

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

Changes to Outputs:
  + creation_time = "5s"

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

  Enter a value: yes

null_resource.previous: Creating...
null_resource.previous: Creation complete after 0s [id=5933671634619443976]
time_sleep.wait_5_seconds: Creating...
time_sleep.wait_50_seconds: Creating...
time_sleep.wait_50_seconds: Creation complete after 5s [id=2023-10-26T21:40:16Z]
time_sleep.wait_5_seconds: Creation complete after 5s [id=2023-10-26T21:40:16Z]
null_resource.next: Creating...
null_resource.next: Creation complete after 0s [id=4539348089142511237]

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

Outputs:

creation_time = "5s"
user@pop-os:~/git/terraform-modules/shared-workspace/workspace1$ terraform destroy

Running apply in Terraform Cloud. Output will stream here. Pressing Ctrl-C
will cancel the remote apply if it's still pending. If the apply started it
will stop streaming the logs, but will not stop the apply running remotely.

Preparing the remote apply...

To view this run in a browser, visit:
https://8080-azbuilder-terrakube-kol6dwnt5ol.ws-us105.gitpod.io/app/simple/test1-remote/runs/2

Waiting for the plan to start...

***************************************
Running Terraform PLAN
***************************************
null_resource.previous: Refreshing state... [id=5933671634619443976]
time_sleep.wait_5_seconds: Refreshing state... [id=2023-10-26T21:40:16Z]
time_sleep.wait_50_seconds: Refreshing state... [id=2023-10-26T21:40:16Z]
null_resource.next: Refreshing state... [id=4539348089142511237]

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

Terraform will perform the following actions:

  # null_resource.next will be destroyed
  - resource "null_resource" "next" {
      - id = "4539348089142511237" -> null
    }

  # null_resource.previous will be destroyed
  - resource "null_resource" "previous" {
      - id = "5933671634619443976" -> null
    }

  # time_sleep.wait_50_seconds will be destroyed
  - resource "time_sleep" "wait_50_seconds" {
      - create_duration = "5s" -> null
      - id              = "2023-10-26T21:40:16Z" -> null
    }

  # time_sleep.wait_5_seconds will be destroyed
  - resource "time_sleep" "wait_5_seconds" {
      - create_duration = "5s" -> null
      - id              = "2023-10-26T21:40:16Z" -> null
    }

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

Changes to Outputs:
  - creation_time = "5s" -> null

Do you really want to destroy all resources in workspace "test1-remote"?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

time_sleep.wait_50_seconds: Destroying... [id=2023-10-26T21:40:16Z]
time_sleep.wait_50_seconds: Destruction complete after 0s
null_resource.next: Destroying... [id=4539348089142511237]
null_resource.next: Destruction complete after 0s
time_sleep.wait_5_seconds: Destroying... [id=2023-10-26T21:40:16Z]
time_sleep.wait_5_seconds: Destruction complete after 0s
null_resource.previous: Destroying... [id=5933671634619443976]
null_resource.previous: Destruction complete after 0s

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

Terraform 1.6.2 (LOCAL)

user@pop-os:~/git/terraform-modules/shared-workspace/workspace1$ terraform -version
Terraform v1.6.2
on linux_amd64
user@pop-os:~/git/terraform-modules/shared-workspace/workspace1$ terraform init

Initializing Terraform Cloud...

Initializing provider plugins...
- Finding latest version of hashicorp/time...
- Finding latest version of hashicorp/null...
- Installing hashicorp/time v0.9.1...
- Installed hashicorp/time v0.9.1 (signed by HashiCorp)
- Installing hashicorp/null v3.2.1...
- Installed hashicorp/null v3.2.1 (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/terraform-modules/shared-workspace/workspace1$ 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.previous will be created
  + resource "null_resource" "previous" {
      + id = (known after apply)
    }

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

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

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

Changes to Outputs:
  + creation_time = "5s"

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

  Enter a value: yes

null_resource.previous: Creating...
null_resource.previous: Creation complete after 0s [id=6386013415808864936]
time_sleep.wait_5_seconds: Creating...
time_sleep.wait_50_seconds: Creating...
time_sleep.wait_50_seconds: Creation complete after 5s [id=2023-10-26T22:03:31Z]
time_sleep.wait_5_seconds: Creation complete after 5s [id=2023-10-26T22:03:31Z]
null_resource.next: Creating...
null_resource.next: Creation complete after 0s [id=3178616526066943110]

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

Outputs:

creation_time = "5s"

user@pop-os:~/git/terraform-modules/shared-workspace/workspace1$ terraform destroy

null_resource.previous: Refreshing state... [id=6386013415808864936]
time_sleep.wait_5_seconds: Refreshing state... [id=2023-10-26T22:03:31Z]
null_resource.next: Refreshing state... [id=3178616526066943110]

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

Terraform will perform the following actions:

  # null_resource.next will be destroyed
  - resource "null_resource" "next" {
      - id = "3178616526066943110" -> null
    }

  # null_resource.previous will be destroyed
  - resource "null_resource" "previous" {
      - id = "6386013415808864936" -> null
    }

  # time_sleep.wait_5_seconds will be destroyed
  - resource "time_sleep" "wait_5_seconds" {
      - create_duration = "5s" -> null
      - id              = "2023-10-26T22:03:31Z" -> null
    }

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

Changes to Outputs:
  - creation_time = "5s" -> null

Do you really want to destroy all resources in workspace "test1"?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

null_resource.next: Destroying... [id=3178616526066943110]
null_resource.next: Destruction complete after 0s
time_sleep.wait_5_seconds: Destroying... [id=2023-10-26T22:03:31Z]
time_sleep.wait_5_seconds: Destruction complete after 0s
null_resource.previous: Destroying... [id=6386013415808864936]
null_resource.previous: Destruction complete after 0s

Destroy complete! Resources: 3 destroyed.

Testing backward compatibility

Terraform 1.5.7 (remote)

user@pop-os:~/git/terraform-modules/shared-workspace/workspace1$ terraform -version
Terraform v1.5.7
on linux_amd64
+ provider registry.terraform.io/hashicorp/null v3.2.1
+ provider registry.terraform.io/hashicorp/time v0.9.1

Your version of Terraform is out of date! The latest version
is 1.6.2. You can update by downloading from https://www.terraform.io/downloads.html
user@pop-os:~/git/terraform-modules/shared-workspace/workspace1$ terraform init

Initializing Terraform Cloud...

No workspaces found.
  
  There are no workspaces with the configured tags (test2)
  in your Terraform Cloud organization. To finish initializing, Terraform needs at
  least one workspace available.
  
  Terraform can create a properly tagged workspace for you now. Please enter a
  name to create a new Terraform Cloud workspace.

  Enter a value: test2-remote


Initializing provider plugins...
- Finding latest version of hashicorp/null...
- Finding latest version of hashicorp/time...
- Installing hashicorp/null v3.2.1...
- Installed hashicorp/null v3.2.1 (signed by HashiCorp)
- Installing hashicorp/time v0.9.1...
- Installed hashicorp/time v0.9.1 (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/terraform-modules/shared-workspace/workspace1$ terraform apply

Running apply in Terraform Cloud. Output will stream here. Pressing Ctrl-C
will cancel the remote apply if it's still pending. If the apply started it
will stop streaming the logs, but will not stop the apply running remotely.

Preparing the remote apply...

To view this run in a browser, visit:
https://8080-azbuilder-terrakube-kol6dwnt5ol.ws-us105.gitpod.io/app/simple/test2-remote/runs/6

Waiting for the plan to start...

***************************************
Running Terraform PLAN
***************************************

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.previous will be created
  + resource "null_resource" "previous" {
      + id = (known after apply)
    }

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

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

Changes to Outputs:
  + creation_time = "5s"

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

  Enter a value: yes

null_resource.previous: Creating...
null_resource.previous: Creation complete after 0s [id=3676940228749361810]
time_sleep.wait_5_seconds: Creating...
time_sleep.wait_5_seconds: Creation complete after 5s [id=2023-10-26T22:09:14Z]
null_resource.next: Creating...
null_resource.next: Creation complete after 0s [id=3471347596921242214]

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

Outputs:

creation_time = "5s"
user@pop-os:~/git/terraform-modules/shared-workspace/workspace1$

user@pop-os:~/git/terraform-modules/shared-workspace/workspace1$ terraform destroy

Running apply in Terraform Cloud. Output will stream here. Pressing Ctrl-C
will cancel the remote apply if it's still pending. If the apply started it
will stop streaming the logs, but will not stop the apply running remotely.

Preparing the remote apply...

To view this run in a browser, visit:
https://8080-azbuilder-terrakube-kol6dwnt5ol.ws-us105.gitpod.io/app/simple/test2-remote/runs/7

Waiting for the plan to start...

***************************************
Running Terraform PLAN
***************************************
null_resource.previous: Refreshing state... [id=3676940228749361810]
time_sleep.wait_5_seconds: Refreshing state... [id=2023-10-26T22:09:14Z]
null_resource.next: Refreshing state... [id=3471347596921242214]

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

Terraform will perform the following actions:

  # null_resource.next will be destroyed
  - resource "null_resource" "next" {
      - id = "3471347596921242214" -> null
    }

  # null_resource.previous will be destroyed
  - resource "null_resource" "previous" {
      - id = "3676940228749361810" -> null
    }

  # time_sleep.wait_5_seconds will be destroyed
  - resource "time_sleep" "wait_5_seconds" {
      - create_duration = "5s" -> null
      - id              = "2023-10-26T22:09:14Z" -> null
    }

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

Changes to Outputs:
  - creation_time = "5s" -> null

Do you really want to destroy all resources in workspace "test2-remote"?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

null_resource.next: Destroying... [id=3471347596921242214]
null_resource.next: Destruction complete after 0s
time_sleep.wait_5_seconds: Destroying... [id=2023-10-26T22:09:14Z]
time_sleep.wait_5_seconds: Destruction complete after 0s
null_resource.previous: Destroying... [id=3676940228749361810]
null_resource.previous: Destruction complete after 0s

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

Terraform 1.5.7 (LOCAL)

user@pop-os:~/git/terraform-modules/shared-workspace/workspace1$ terraform version
Terraform v1.5.7
on linux_amd64

Your version of Terraform is out of date! The latest version
is 1.6.2. You can update by downloading from https://www.terraform.io/downloads.html
user@pop-os:~/git/terraform-modules/shared-workspace/workspace1$ terraform init

Initializing Terraform Cloud...

Initializing provider plugins...
- Finding latest version of hashicorp/time...
- Finding latest version of hashicorp/null...
- Installing hashicorp/time v0.9.1...
- Installed hashicorp/time v0.9.1 (signed by HashiCorp)
- Installing hashicorp/null v3.2.1...
- Installed hashicorp/null v3.2.1 (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.

╷
│ Warning: Provider development overrides are in effect
│ 
│ The following provider development overrides are set in the CLI configuration:
│  - alfespa17/terrakube in /home/user/go/bin
│ 
│ Skip terraform init when using provider development overrides. It is not necessary and may
│ error unexpectedly.
╵

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/terraform-modules/shared-workspace/workspace1$ terraform apply
╷
│ Warning: Provider development overrides are in effect
│ 
│ The following provider development overrides are set in the CLI configuration:
│  - alfespa17/terrakube in /home/user/go/bin
│ 
│ The behavior may therefore not match any released version of the provider and applying
│ changes may cause the state to become incompatible with published releases.
╵

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.previous will be created
  + resource "null_resource" "previous" {
      + id = (known after apply)
    }

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

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

Changes to Outputs:
  + creation_time = "5s"

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

  Enter a value: yes

null_resource.previous: Creating...
null_resource.previous: Creation complete after 0s [id=5055717965929954809]
time_sleep.wait_5_seconds: Creating...
time_sleep.wait_5_seconds: Creation complete after 5s [id=2023-10-26T22:15:19Z]
null_resource.next: Creating...
null_resource.next: Creation complete after 0s [id=8134779359410785063]

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

Outputs:

creation_time = "5s"
user@pop-os:~/git/terraform-modules/shared-workspace/workspace1$ terraform destroy
╷
│ Warning: Provider development overrides are in effect
│ 
│ The following provider development overrides are set in the CLI configuration:
│  - alfespa17/terrakube in /home/user/go/bin
│ 
│ The behavior may therefore not match any released version of the provider and applying
│ changes may cause the state to become incompatible with published releases.
╵
null_resource.previous: Refreshing state... [id=5055717965929954809]
time_sleep.wait_5_seconds: Refreshing state... [id=2023-10-26T22:15:19Z]
null_resource.next: Refreshing state... [id=8134779359410785063]

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

Terraform will perform the following actions:

  # null_resource.next will be destroyed
  - resource "null_resource" "next" {
      - id = "8134779359410785063" -> null
    }

  # null_resource.previous will be destroyed
  - resource "null_resource" "previous" {
      - id = "5055717965929954809" -> null
    }

  # time_sleep.wait_5_seconds will be destroyed
  - resource "time_sleep" "wait_5_seconds" {
      - create_duration = "5s" -> null
      - id              = "2023-10-26T22:15:19Z" -> null
    }

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

Changes to Outputs:
  - creation_time = "5s" -> null

Do you really want to destroy all resources in workspace "test2-local"?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

null_resource.next: Destroying... [id=8134779359410785063]
null_resource.next: Destruction complete after 0s
time_sleep.wait_5_seconds: Destroying... [id=2023-10-26T22:15:19Z]
time_sleep.wait_5_seconds: Destruction complete after 0s
null_resource.previous: Destroying... [id=5055717965929954809]
null_resource.previous: Destruction complete after 0s

Destroy complete! Resources: 3 destroyed.

Fix #532

@sonarcloud
Copy link

sonarcloud bot commented Oct 26, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

12.0% 12.0% Coverage
0.0% 0.0% Duplication

@alfespa17 alfespa17 merged commit 00d1b03 into main Oct 26, 2023
4 checks passed
@alfespa17 alfespa17 deleted the fix-1.6.X branch October 26, 2023 22:47
@alfespa17 alfespa17 added this to the 2.17.0 milestone Oct 26, 2023
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.

Error with terraform remote backend 1.6.X
1 participant