From e0af3e25e0d2b2b37b76d4d527da1cdcf2429107 Mon Sep 17 00:00:00 2001 From: Nick Fagerlund Date: Mon, 26 Jun 2023 17:47:43 -0700 Subject: [PATCH] Add `cloudplan.RemotePlanJSON` wrapper struct for keeping plan metadata together --- internal/cloud/cloudplan/remote_plan_json.go | 39 ++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 internal/cloud/cloudplan/remote_plan_json.go diff --git a/internal/cloud/cloudplan/remote_plan_json.go b/internal/cloud/cloudplan/remote_plan_json.go new file mode 100644 index 0000000000..9b378eee4f --- /dev/null +++ b/internal/cloud/cloudplan/remote_plan_json.go @@ -0,0 +1,39 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package cloudplan + +import ( + "github.com/hashicorp/terraform/internal/plans" +) + +// RemotePlanJSON is a wrapper struct that associates a pre-baked JSON plan with +// several pieces of metadata that can't be derived directly from the JSON +// contents and must instead be discovered from a tfe.Run or tfe.Plan. The +// wrapper is useful for moving data between the Cloud backend (which is the +// only thing able to fetch the JSON and determine values for the metadata) and +// the command.ShowCommand and views.Show interface (which need to have all of +// this information together). +type RemotePlanJSON struct { + // The raw bytes of json we got from the API. + JSONBytes []byte + // Indicates whether the json bytes are the "redacted json plan" format, or + // the unredacted stable "external json plan" format. These formats are + // actually very different under the hood; the redacted one can be decoded + // directly into a jsonformat.Plan struct and is intended for formatting a + // plan for human consumption, while the unredacted one matches what is + // returned by the jsonplan.Marshal() function, cannot be directly decoded + // into a public type (it's actually a jsonplan.plan struct), and will + // generally be spat back out verbatim. + Redacted bool + // Normal/destroy/refresh. Required by (jsonformat.Renderer).RenderHumanPlan. + Mode plans.Mode + // Unchanged/errored. Required by (jsonformat.Renderer).RenderHumanPlan. + Qualities []plans.Quality + // A human-readable header with a link to view the associated run in the + // Terraform Cloud UI. + RunHeader string + // A human-readable footer with information relevant to the likely next + // actions for this plan. + RunFooter string +}