Closed stanleyz closed 1 week ago
I tested this and I found a little issue for example if I run a run two terraform commands the second command should be in waiting state until the first is completed example:
This operation is running fine but once terraform asked for confirmation all the other jobs should be waiting in the queue.
user@pop-os:~/git/simple-terraform$ terraform apply
Running apply in HCP Terraform. 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://terrakube-api.minikube.net/app/simple/locked-remote/runs/run-139
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.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.next4 will be created
+ resource "null_resource" "next4" {
+ 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 = "2m"
+ destroy_duration = "45s"
+ 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: 7 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ creation_time = "2m"
+ fake_data = {
+ data = "Hello World"
+ resource = {
+ resource1 = "fake"
}
}
Do you want to perform these actions in workspace "locked-remote"?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value:
For example I ran a second operation at the same time, the terraform command was locked and waiting as you can see below, but once the first job asked for confirmation this plan was executed and it should be waiting for the first one to be completed, failed or cancelled.
user@pop-os:~/git/simple-terraform$ terraform apply
Running apply in HCP Terraform. 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://terrakube-api.minikube.net/app/simple/locked-remote/runs/run-140
Waiting for -7 queued run(s) to finish before starting...
Waiting for -7 queued run(s) to finish before starting... (30s elapsed)
Waiting for -7 queued run(s) to finish before starting... (1m0s elapsed)
***************************************
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.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.next4 will be created
+ resource "null_resource" "next4" {
+ 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 = "2m"
+ destroy_duration = "45s"
+ 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: 7 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ creation_time = "2m"
+ fake_data = {
+ data = "Hello World"
+ resource = {
+ resource1 = "fake"
}
}
I think that if you add the "waitingForApproval" status to the logic that you have updated that should fix it.
This is an example using TFC.
This is waiting for confirmation after the plan is completed
user@pop-os:~/git/simple-terraform$ terraform apply
Running apply in HCP Terraform. 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://app.terraform.io/app/alfespa17/locked-remote/runs/run-TDhGFxb4oEPJEvha
Waiting for the plan to start...
Terraform v1.9.5
on linux_amd64
Initializing plugins and modules...
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.next4 will be created
+ resource "null_resource" "next4" {
+ 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 = "2m"
+ destroy_duration = "45s"
+ 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: 7 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ creation_time = "2m"
+ fake_data = {
+ data = "Hello World"
+ resource = {
+ resource1 = "fake"
}
}
Do you want to perform these actions in workspace "locked-remote"?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value:
it is being queue and waiting for the first to be completed:
user@pop-os:~/git/simple-terraform$ terraform apply
Running apply in HCP Terraform. 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://app.terraform.io/app/alfespa17/locked-remote/runs/run-AantdC2opyRBsbqV
Waiting for 1 run(s) to finish before being queued...
Waiting for 1 run(s) to finish before being queued... (30s elapsed)
Waiting for 1 run(s) to finish before being queued... (1m0s elapsed)
Waiting for 1 run(s) to finish before being queued... (1m30s elapsed)
This change takes a parameter of the number of executor replicas and uses that as the capacity for the whole Terrakube instance. This could be improved later on if more different types of agents are supported.
fix #1285