github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/resource/stack/plan.go (about) 1 package stack 2 3 import ( 4 "github.com/pulumi/pulumi/pkg/v3/resource/deploy" 5 "github.com/pulumi/pulumi/sdk/v3/go/common/apitype" 6 "github.com/pulumi/pulumi/sdk/v3/go/common/display" 7 "github.com/pulumi/pulumi/sdk/v3/go/common/resource" 8 "github.com/pulumi/pulumi/sdk/v3/go/common/resource/config" 9 ) 10 11 func SerializePlanDiff( 12 diff deploy.PlanDiff, 13 enc config.Encrypter, 14 showSecrets bool) (apitype.PlanDiffV1, error) { 15 16 adds, err := SerializeProperties(diff.Adds, enc, showSecrets) 17 if err != nil { 18 return apitype.PlanDiffV1{}, err 19 } 20 21 updates, err := SerializeProperties(diff.Updates, enc, showSecrets) 22 if err != nil { 23 return apitype.PlanDiffV1{}, err 24 } 25 26 deletes := make([]string, len(diff.Deletes)) 27 for i := range deletes { 28 deletes[i] = string(diff.Deletes[i]) 29 } 30 31 return apitype.PlanDiffV1{ 32 Adds: adds, 33 Updates: updates, 34 Deletes: deletes, 35 }, nil 36 } 37 38 func DeserializePlanDiff( 39 diff apitype.PlanDiffV1, 40 dec config.Decrypter, 41 enc config.Encrypter) (deploy.PlanDiff, error) { 42 43 adds, err := DeserializeProperties(diff.Adds, dec, enc) 44 if err != nil { 45 return deploy.PlanDiff{}, err 46 } 47 48 updates, err := DeserializeProperties(diff.Updates, dec, enc) 49 if err != nil { 50 return deploy.PlanDiff{}, err 51 } 52 53 deletes := make([]resource.PropertyKey, len(diff.Deletes)) 54 for i := range deletes { 55 deletes[i] = resource.PropertyKey(diff.Deletes[i]) 56 } 57 58 return deploy.PlanDiff{Adds: adds, Updates: updates, Deletes: deletes}, nil 59 } 60 61 func SerializeResourcePlan( 62 plan *deploy.ResourcePlan, 63 enc config.Encrypter, 64 showSecrets bool) (apitype.ResourcePlanV1, error) { 65 66 var outputs map[string]interface{} 67 if plan.Outputs != nil { 68 outs, err := SerializeProperties(plan.Outputs, enc, showSecrets) 69 if err != nil { 70 return apitype.ResourcePlanV1{}, err 71 } 72 outputs = outs 73 } 74 75 steps := make([]apitype.OpType, len(plan.Ops)) 76 for i, op := range plan.Ops { 77 steps[i] = apitype.OpType(op) 78 } 79 80 var goal *apitype.GoalV1 81 if plan.Goal != nil { 82 inputDiff, err := SerializePlanDiff(plan.Goal.InputDiff, enc, showSecrets) 83 if err != nil { 84 return apitype.ResourcePlanV1{}, err 85 } 86 87 outputDiff, err := SerializePlanDiff(plan.Goal.OutputDiff, enc, showSecrets) 88 if err != nil { 89 return apitype.ResourcePlanV1{}, err 90 } 91 92 goal = &apitype.GoalV1{ 93 Type: plan.Goal.Type, 94 Name: plan.Goal.Name, 95 Custom: plan.Goal.Custom, 96 InputDiff: inputDiff, 97 OutputDiff: outputDiff, 98 Parent: plan.Goal.Parent, 99 Protect: plan.Goal.Protect, 100 Dependencies: plan.Goal.Dependencies, 101 Provider: plan.Goal.Provider, 102 PropertyDependencies: plan.Goal.PropertyDependencies, 103 DeleteBeforeReplace: plan.Goal.DeleteBeforeReplace, 104 IgnoreChanges: plan.Goal.IgnoreChanges, 105 AdditionalSecretOutputs: plan.Goal.AdditionalSecretOutputs, 106 Aliases: plan.Goal.Aliases, 107 ID: plan.Goal.ID, 108 CustomTimeouts: plan.Goal.CustomTimeouts, 109 } 110 } 111 112 return apitype.ResourcePlanV1{ 113 Goal: goal, 114 Seed: plan.Seed, 115 Steps: steps, 116 Outputs: outputs, 117 }, nil 118 } 119 120 func SerializePlan(plan *deploy.Plan, enc config.Encrypter, showSecrets bool) (apitype.DeploymentPlanV1, error) { 121 resourcePlans := map[resource.URN]apitype.ResourcePlanV1{} 122 for urn, plan := range plan.ResourcePlans { 123 serializedPlan, err := SerializeResourcePlan(plan, enc, showSecrets) 124 if err != nil { 125 return apitype.DeploymentPlanV1{}, err 126 } 127 resourcePlans[urn] = serializedPlan 128 } 129 130 return apitype.DeploymentPlanV1{ 131 Manifest: plan.Manifest.Serialize(), 132 ResourcePlans: resourcePlans, 133 Config: plan.Config, 134 }, nil 135 } 136 137 func DeserializeResourcePlan( 138 plan apitype.ResourcePlanV1, 139 dec config.Decrypter, 140 enc config.Encrypter) (*deploy.ResourcePlan, error) { 141 142 var goal *deploy.GoalPlan 143 if plan.Goal != nil { 144 inputDiff, err := DeserializePlanDiff(plan.Goal.InputDiff, dec, enc) 145 if err != nil { 146 return nil, err 147 } 148 149 outputDiff, err := DeserializePlanDiff(plan.Goal.OutputDiff, dec, enc) 150 if err != nil { 151 return nil, err 152 } 153 154 goal = &deploy.GoalPlan{ 155 Type: plan.Goal.Type, 156 Name: plan.Goal.Name, 157 Custom: plan.Goal.Custom, 158 InputDiff: inputDiff, 159 OutputDiff: outputDiff, 160 Parent: plan.Goal.Parent, 161 Protect: plan.Goal.Protect, 162 Dependencies: plan.Goal.Dependencies, 163 Provider: plan.Goal.Provider, 164 PropertyDependencies: plan.Goal.PropertyDependencies, 165 DeleteBeforeReplace: plan.Goal.DeleteBeforeReplace, 166 IgnoreChanges: plan.Goal.IgnoreChanges, 167 AdditionalSecretOutputs: plan.Goal.AdditionalSecretOutputs, 168 Aliases: plan.Goal.Aliases, 169 ID: plan.Goal.ID, 170 CustomTimeouts: plan.Goal.CustomTimeouts, 171 } 172 } 173 174 var outputs resource.PropertyMap 175 if plan.Outputs != nil { 176 outs, err := DeserializeProperties(plan.Outputs, dec, enc) 177 if err != nil { 178 return nil, err 179 } 180 outputs = outs 181 } 182 183 ops := make([]display.StepOp, len(plan.Steps)) 184 for i, op := range plan.Steps { 185 ops[i] = display.StepOp(op) 186 } 187 188 return &deploy.ResourcePlan{ 189 Goal: goal, 190 Seed: plan.Seed, 191 Ops: ops, 192 Outputs: outputs, 193 }, nil 194 } 195 196 func DeserializePlan(plan apitype.DeploymentPlanV1, dec config.Decrypter, enc config.Encrypter) (*deploy.Plan, error) { 197 manifest, err := deploy.DeserializeManifest(plan.Manifest) 198 if err != nil { 199 return nil, err 200 } 201 202 deserializedPlan := &deploy.Plan{ 203 Config: plan.Config, 204 Manifest: *manifest, 205 ResourcePlans: make(map[resource.URN]*deploy.ResourcePlan), 206 } 207 for urn, resourcePlan := range plan.ResourcePlans { 208 deserializedResourcePlan, err := DeserializeResourcePlan(resourcePlan, dec, enc) 209 if err != nil { 210 return nil, err 211 } 212 deserializedPlan.ResourcePlans[urn] = deserializedResourcePlan 213 } 214 return deserializedPlan, nil 215 }