Browse Source

fix bug that prevented terraform statuses from being reported for many

resources
master
forest 2 years ago
parent
commit
ef6ac361a8
  1. 12
      automation/terraformActions.go
  2. 21
      main.go

12
automation/terraformActions.go

@ -62,8 +62,9 @@ type ResourceChangeFilter struct {
type TerraformShowResourceChange struct {
TerraformShowResource
ModuleAddress string `json:"module_address"`
Change TerraformShowChangeSpec `json:"change"`
ModuleAddress string `json:"module_address"`
Change TerraformShowChangeSpec `json:"change"`
HasCorrespondingResource bool
}
type TerraformShowChangeSpec struct {
@ -186,6 +187,7 @@ func TerraformPlanAndApply(
changedResource.Type = resourceWithValues.Type
changedResource.Name = resourceWithValues.Name
changedResource.Values = resourceWithValues.Values
changedResource.HasCorrespondingResource = true
} else {
// TODO this can happen when a resource is deleted ( like an extra ssh key being deleted )
// for example:
@ -222,7 +224,7 @@ func TerraformPlanAndApply(
// json, err := json.MarshalIndent(simpleStatus, "", " ")
// if err != nil {
// return nil, errors.Wrap(err, "can't GenerateTerraformPlan because can't json.Marshal the simpleStatus")
// return nil, nil, "", errors.Wrap(err, "can't GenerateTerraformPlan because can't json.Marshal the simpleStatus")
// }
// log.Println(string(json))
@ -699,10 +701,10 @@ func makeSimplifiedTerraformStatus(
resourceIndexRegexp := regexp.MustCompile(`\[([0-9]+)\]$`)
for _, resourceChange := range tfShow.ResourceChanges {
// resourceChange.Values should have come from the corresponding resource.
// if there is no corresponding resource, I think it should be nil and that means it was
// a deposed resource or something... lets omit it
if resourceChange.Values != nil {
if !resourceChange.HasCorrespondingResource {
continue
}

21
main.go

@ -143,7 +143,7 @@ func terraformBuild(
success := false
for status := range statusChannel {
json, err := json.MarshalIndent(status, "", " ")
statusJson, err := json.MarshalIndent(status, "", " ")
if err != nil {
return []string{}, false, err
}
@ -151,10 +151,21 @@ func terraformBuild(
newLog := strings.TrimPrefix(status.Log, lastLog)
lastLog = status.Log
log.Println(newLog)
// log.Println(string(json))
err = global.storage.Put(fmt.Sprintf("rootsystem/terraform/%s/status.json", terraformConfig.TerraformProject), json)
//log.Printf("len(newLog): %d\n", len(newLog))
// status1 := automation.TerraformApplyResult{
// Error: status.Error,
// Success: status.Success,
// Complete: status.Complete,
// Status: status.Status,
// }
// statusJson1, err := json.MarshalIndent(status1, "", " ")
// if err != nil {
// return []string{}, false, err
// }
// log.Println(string(statusJson1))
err = global.storage.Put(fmt.Sprintf("rootsystem/terraform/%s/status.json", terraformConfig.TerraformProject), statusJson)
if err != nil {
log.Printf("can't upload terraform status update to object storage: %+v", err)
}

Loading…
Cancel
Save