|
1 | 1 | if err := waitForAttachmentToBeProvisioned(d, config, d.Timeout(schema.TimeoutCreate)); err != nil {
|
2 | 2 | return fmt.Errorf("Error waiting for InterconnectAttachment %q to be provisioned: %q", d.Get("name").(string), err)
|
3 | 3 | }
|
| 4 | + |
| 5 | +{{- if $.HasLabelsField }} |
| 6 | +if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) { |
| 7 | + labels := d.Get("labels") |
| 8 | + terraformLables := d.Get("terraform_labels") |
| 9 | + |
| 10 | + // Labels cannot be set in a create. We'll have to set them here. |
| 11 | + err = resource{{$.ResourceName}}Read(d, meta) |
| 12 | + if err != nil { |
| 13 | + return err |
| 14 | + } |
| 15 | + |
| 16 | + obj := make(map[string]interface{}) |
| 17 | + // d.Get("effective_labels") will have been overridden by the Read call. |
| 18 | + labelsProp, err := expand{{$.ResourceName}}EffectiveLabels(v, d, config) |
| 19 | + if err != nil { |
| 20 | + return err |
| 21 | + } |
| 22 | + obj["labels"] = labelsProp |
| 23 | + labelFingerprintProp := d.Get("label_fingerprint") |
| 24 | + obj["labelFingerprint"] = labelFingerprintProp |
| 25 | + |
| 26 | + url, err = tpgresource.ReplaceVars(d, config, "{{"{{"}}{{$.ProductMetadata.Name}}BasePath{{"}}"}}{{$.SelfLinkUri}}/setLabels") |
| 27 | + if err != nil { |
| 28 | + return err |
| 29 | + } |
| 30 | + res, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| 31 | + Config: config, |
| 32 | + Method: "POST", |
| 33 | + Project: project, |
| 34 | + RawURL: url, |
| 35 | + UserAgent: userAgent, |
| 36 | + Body: obj, |
| 37 | + {{- if $.ErrorRetryPredicates }} |
| 38 | + ErrorRetryPredicates: []transport_tpg.RetryErrorPredicateFunc{ {{- join $.ErrorRetryPredicates "," -}} }, |
| 39 | + {{- end }} |
| 40 | + {{- if $.ErrorAbortPredicates }} |
| 41 | + ErrorAbortPredicates: []transport_tpg.RetryErrorPredicateFunc{ {{- join $.ErrorAbortPredicates "," -}} }, |
| 42 | + {{- end }} |
| 43 | + }) |
| 44 | + if err != nil { |
| 45 | + return fmt.Errorf("Error adding labels to {{$.ResourceName}} %q: %s", d.Id(), err) |
| 46 | + } |
| 47 | + |
| 48 | + err = ComputeOperationWaitTime( |
| 49 | + config, res, project, "Updating {{$.ResourceName}} Labels", userAgent, |
| 50 | + d.Timeout(schema.TimeoutUpdate)) |
| 51 | + |
| 52 | + if err != nil { |
| 53 | + return err |
| 54 | + } |
| 55 | + |
| 56 | + // Set back the labels field, as it is needed to decide the value of "labels" in the state in the read function. |
| 57 | + if err := d.Set("labels", labels); err != nil { |
| 58 | + return fmt.Errorf("Error setting back labels: %s", err) |
| 59 | + } |
| 60 | + |
| 61 | + // Set back the terraform_labels field, as it is needed to decide the value of "terraform_labels" in the state in the read function. |
| 62 | + if err := d.Set("terraform_labels", terraformLables); err != nil { |
| 63 | + return fmt.Errorf("Error setting back terraform_labels: %s", err) |
| 64 | + } |
| 65 | + |
| 66 | + // Set back the effective_labels field, as it is needed to decide the value of "effective_labels" in the state in the read function. |
| 67 | + if err := d.Set("effective_labels", v); err != nil { |
| 68 | + return fmt.Errorf("Error setting back effective_labels: %s", err) |
| 69 | + } |
| 70 | +} |
| 71 | +{{- end }} |
0 commit comments