Issues icon indicating copy to clipboard operation
Issues copied to clipboard

Allow output of Plan Terraform step to be used as Apply

Open shaunmarx opened this issue 7 years ago • 3 comments

The terraform plan step currently generates the associated plan and provides it as an output to be shown in a manual intervention step, however it does not use the generated plan as part of the apply step if present and assumes the original template is the same as the generated plan which may not be entirely the case if things have changed in the interim.

Source: https://secure.helpscout.net/conversation/581656122?folderId=557077

shaunmarx avatar May 16 '18 23:05 shaunmarx

It would be good to have this functionality out of the box with Octopus steps, where plan file generated by "Plan a Terraform template" can be feed to "Apply a Terraform template" even with manual intervention in between.

rhollins avatar Jul 11 '18 13:07 rhollins

I've tried to do it manually with no luck:

Server version: 2019.11.3+Branch.tags-2019.11.3.Sha.18e9e62d1c97e2e32ddf80d5a6637c2b507f191c

Plan runs as follows:

"C:\terraform\terraform.exe" init -no-color -get-plugins=true -backend-config="access_key=********" -backend-config="secret_key=********"

"C:\terraform\terraform.exe" plan -no-color -detailed-exitcode -var="kubernetes_service_account_token=********" -var="secrets_credentials={access_key="""********""",secret_key="""********"""}" -out="C:\tmp\Deployments-1055695.tfplan"

And Apply fails like this:

"C:\terraform\terraform.exe" init -no-color -get-plugins=true -backend-config="access_key=********" -backend-config="secret_key=********"

00:43:18   Info     |       Terraform has been successfully initialized!
00:43:18   Info     |       "C:\terraform\terraform.exe" apply -no-color -auto-approve -parallelism=1 -var="kubernetes_service_account_token=********" -var="secrets_credentials={access_key="""********""",secret_key="""********"""}" "C:\tmp\Deployments-1055695.tfplan"
00:43:18   Error    |       Calamari.Integration.Processes.CommandLineException: The following command: "C:\terraform\terraform.exe" apply -no-color -auto-approve -parallelism=1 -var="kubernetes_service_account_token=********" -var="secrets_credentials={access_key="""********""",secret_key="""********"""}" "C:\tmp\Deployments-1055695.tfplan"
00:43:18   Error    |       With the working directory of: C:\Octopus\Work\20200220214312-1479114-62\staging\terraform\yandex\environments\staging\
00:43:18   Error    |       Failed with exit code: 1
00:43:18   Error    |       at Calamari.Integration.Processes.CommandResult.VerifySuccess()
00:43:18   Error    |       at Calamari.Terraform.TerraformCLIExecutor.ExecuteCommand(String[] arguments)
00:43:18   Error    |       at Calamari.Terraform.ApplyTerraformConvention.Execute(RunningDeployment deployment, Dictionary`2 environmentVariables)
00:43:18   Error    |       at Calamari.Terraform.TerraformConvention.<InstallAsync>d__4.MoveNext()
00:43:18   Error    |       --- End of stack trace from previous location where exception was thrown ---
00:43:18   Error    |       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
00:43:18   Error    |       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
00:43:18   Error    |       at Calamari.Terraform.TerraformConvention.Install(RunningDeployment deployment)
00:43:18   Error    |       at Calamari.Deployment.ConventionProcessor.RunInstallConventions()
00:43:18   Error    |       at Calamari.Deployment.ConventionProcessor.RunConventions()
00:43:18   Error    |       Running rollback conventions...
00:43:18   Error    |       The following command: "C:\terraform\terraform.exe" apply -no-color -auto-approve -parallelism=1 -var="kubernetes_service_account_token=********" -var="secrets_credentials={access_key="""********""",secret_key="""********"""}" "C:\tmp\Deployments-1055695.tfplan"
00:43:18   Error    |       With the working directory of: C:\Octopus\Work\20200220214312-1479114-62\staging\terraform\yandex\environments\staging\
00:43:18   Error    |       Failed with exit code: 1
00:43:18   Error    |       Calamari.Integration.Processes.CommandLineException
00:43:18   Error    |       at Calamari.Integration.Processes.CommandResult.VerifySuccess()
00:43:18   Error    |       at Calamari.Terraform.TerraformCLIExecutor.ExecuteCommand(String[] arguments)
00:43:18   Error    |       at Calamari.Terraform.ApplyTerraformConvention.Execute(RunningDeployment deployment, Dictionary`2 environmentVariables)
00:43:18   Error    |       at Calamari.Terraform.TerraformConvention.<InstallAsync>d__4.MoveNext()
00:43:18   Error    |       --- End of stack trace from previous location where exception was thrown ---
00:43:18   Error    |       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
00:43:18   Error    |       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
00:43:18   Error    |       at Calamari.Terraform.TerraformConvention.Install(RunningDeployment deployment)
00:43:18   Error    |       at Calamari.Deployment.ConventionProcessor.RunInstallConventions()
00:43:18   Error    |       at Calamari.Deployment.ConventionProcessor.RunConventions()
00:43:18   Error    |       at Calamari.Terraform.TerraformCommand.Execute(String[] commandLineArguments)
00:43:18   Error    |       at Calamari.Program.Execute(String[] args)
00:43:18   Verbose  |       Process C:\Windows\system32\WindowsPowershell\v1.0\PowerShell.exe in C:\Octopus\Work\20200220214312-1479114-62 exited with code 100

clain23 avatar Feb 20 '20 21:02 clain23

Hello, we're currently using Octopus Deploy in day to day operation. I would like to as if this feature is going to be implemented some time in the future? It would very much increase safety of our deployments.

marcin-trojanowski avatar Apr 22 '24 10:04 marcin-trojanowski