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