go-tfe icon indicating copy to clipboard operation
go-tfe copied to clipboard

How to to check for allowed transitions?

Open dkirrane opened this issue 2 years ago • 1 comments

What is the correct way to check if a plan can be applied?

When I tried to apply the plan below it fails with transition not allowed Here is the Plan output in json (abbreviated). This plan only had changes to output values.

{
    "data": {
        "id": "plan-xyz"
        "type": "plans",
        "attributes": {
            "has-changes": true,
            "status": "finished",
            "resource-additions": 0,
            "resource-changes": 0,
            "resource-destructions": 0,
            "actions": {
                "is-exportable": true
            }
        }
    }
}

dkirrane avatar Sep 21 '22 15:09 dkirrane

Hi @dkirrane

There are a couple ways to find out if a plan can be applied. Note that the checks mentioned below are on the Run not the Plan.

  • Check that the Run.Actions has it’s IsConfirmable attribute set to true, a plan will not be applied if it is not confirmable.(https://pkg.go.dev/github.com/hashicorp/go-tfe#RunActions)
  • Check that the PlanOnly attribute of the run is false. (https://pkg.go.dev/github.com/hashicorp/go-tfe#Run)
  • Check that the Run.Status is not one of the terminal statuses e.g planned_and_finished, see docs (https://www.terraform.io/cloud-docs/api-docs/run#run-states)

Uk1288 avatar Sep 21 '22 19:09 Uk1288

Closing this issue. Please reach out if you have more questions!

annawinkler avatar Feb 07 '23 22:02 annawinkler