/
interconnect_attachment.go
executable file
·675 lines (584 loc) · 24 KB
/
interconnect_attachment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
// Copyright 2023 Google LLC. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package compute
import (
"context"
"crypto/sha256"
"encoding/json"
"fmt"
"time"
"google.golang.org/api/googleapi"
"github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
)
type InterconnectAttachment struct {
Description *string `json:"description"`
SelfLink *string `json:"selfLink"`
Id *int64 `json:"id"`
Name *string `json:"name"`
Interconnect *string `json:"interconnect"`
Router *string `json:"router"`
Region *string `json:"region"`
Mtu *int64 `json:"mtu"`
PrivateInterconnectInfo *InterconnectAttachmentPrivateInterconnectInfo `json:"privateInterconnectInfo"`
OperationalStatus *InterconnectAttachmentOperationalStatusEnum `json:"operationalStatus"`
CloudRouterIPAddress *string `json:"cloudRouterIPAddress"`
CustomerRouterIPAddress *string `json:"customerRouterIPAddress"`
Type *InterconnectAttachmentTypeEnum `json:"type"`
PairingKey *string `json:"pairingKey"`
AdminEnabled *bool `json:"adminEnabled"`
VlanTag8021q *int64 `json:"vlanTag8021q"`
EdgeAvailabilityDomain *InterconnectAttachmentEdgeAvailabilityDomainEnum `json:"edgeAvailabilityDomain"`
CandidateSubnets []string `json:"candidateSubnets"`
Bandwidth *InterconnectAttachmentBandwidthEnum `json:"bandwidth"`
PartnerMetadata *InterconnectAttachmentPartnerMetadata `json:"partnerMetadata"`
State *InterconnectAttachmentStateEnum `json:"state"`
PartnerAsn *int64 `json:"partnerAsn"`
Encryption *InterconnectAttachmentEncryptionEnum `json:"encryption"`
IpsecInternalAddresses []string `json:"ipsecInternalAddresses"`
DataplaneVersion *int64 `json:"dataplaneVersion"`
SatisfiesPzs *bool `json:"satisfiesPzs"`
Project *string `json:"project"`
}
func (r *InterconnectAttachment) String() string {
return dcl.SprintResource(r)
}
// The enum InterconnectAttachmentOperationalStatusEnum.
type InterconnectAttachmentOperationalStatusEnum string
// InterconnectAttachmentOperationalStatusEnumRef returns a *InterconnectAttachmentOperationalStatusEnum with the value of string s
// If the empty string is provided, nil is returned.
func InterconnectAttachmentOperationalStatusEnumRef(s string) *InterconnectAttachmentOperationalStatusEnum {
v := InterconnectAttachmentOperationalStatusEnum(s)
return &v
}
func (v InterconnectAttachmentOperationalStatusEnum) Validate() error {
if string(v) == "" {
// Empty enum is okay.
return nil
}
for _, s := range []string{"OS_ACTIVE", "OS_UNPROVISIONED"} {
if string(v) == s {
return nil
}
}
return &dcl.EnumInvalidError{
Enum: "InterconnectAttachmentOperationalStatusEnum",
Value: string(v),
Valid: []string{},
}
}
// The enum InterconnectAttachmentTypeEnum.
type InterconnectAttachmentTypeEnum string
// InterconnectAttachmentTypeEnumRef returns a *InterconnectAttachmentTypeEnum with the value of string s
// If the empty string is provided, nil is returned.
func InterconnectAttachmentTypeEnumRef(s string) *InterconnectAttachmentTypeEnum {
v := InterconnectAttachmentTypeEnum(s)
return &v
}
func (v InterconnectAttachmentTypeEnum) Validate() error {
if string(v) == "" {
// Empty enum is okay.
return nil
}
for _, s := range []string{"PATH", "OTHER", "PARAMETER"} {
if string(v) == s {
return nil
}
}
return &dcl.EnumInvalidError{
Enum: "InterconnectAttachmentTypeEnum",
Value: string(v),
Valid: []string{},
}
}
// The enum InterconnectAttachmentEdgeAvailabilityDomainEnum.
type InterconnectAttachmentEdgeAvailabilityDomainEnum string
// InterconnectAttachmentEdgeAvailabilityDomainEnumRef returns a *InterconnectAttachmentEdgeAvailabilityDomainEnum with the value of string s
// If the empty string is provided, nil is returned.
func InterconnectAttachmentEdgeAvailabilityDomainEnumRef(s string) *InterconnectAttachmentEdgeAvailabilityDomainEnum {
v := InterconnectAttachmentEdgeAvailabilityDomainEnum(s)
return &v
}
func (v InterconnectAttachmentEdgeAvailabilityDomainEnum) Validate() error {
if string(v) == "" {
// Empty enum is okay.
return nil
}
for _, s := range []string{"AVAILABILITY_DOMAIN_ANY", "AVAILABILITY_DOMAIN_1", "AVAILABILITY_DOMAIN_2"} {
if string(v) == s {
return nil
}
}
return &dcl.EnumInvalidError{
Enum: "InterconnectAttachmentEdgeAvailabilityDomainEnum",
Value: string(v),
Valid: []string{},
}
}
// The enum InterconnectAttachmentBandwidthEnum.
type InterconnectAttachmentBandwidthEnum string
// InterconnectAttachmentBandwidthEnumRef returns a *InterconnectAttachmentBandwidthEnum with the value of string s
// If the empty string is provided, nil is returned.
func InterconnectAttachmentBandwidthEnumRef(s string) *InterconnectAttachmentBandwidthEnum {
v := InterconnectAttachmentBandwidthEnum(s)
return &v
}
func (v InterconnectAttachmentBandwidthEnum) Validate() error {
if string(v) == "" {
// Empty enum is okay.
return nil
}
for _, s := range []string{"BPS_50M", "BPS_100M", "BPS_200M", "BPS_300M", "BPS_400M", "BPS_500M", "BPS_1G", "BPS_2G", "BPS_5G", "BPS_10G", "BPS_20G", "BPS_50G"} {
if string(v) == s {
return nil
}
}
return &dcl.EnumInvalidError{
Enum: "InterconnectAttachmentBandwidthEnum",
Value: string(v),
Valid: []string{},
}
}
// The enum InterconnectAttachmentStateEnum.
type InterconnectAttachmentStateEnum string
// InterconnectAttachmentStateEnumRef returns a *InterconnectAttachmentStateEnum with the value of string s
// If the empty string is provided, nil is returned.
func InterconnectAttachmentStateEnumRef(s string) *InterconnectAttachmentStateEnum {
v := InterconnectAttachmentStateEnum(s)
return &v
}
func (v InterconnectAttachmentStateEnum) Validate() error {
if string(v) == "" {
// Empty enum is okay.
return nil
}
for _, s := range []string{"DEPRECATED", "OBSOLETE", "DELETED", "ACTIVE"} {
if string(v) == s {
return nil
}
}
return &dcl.EnumInvalidError{
Enum: "InterconnectAttachmentStateEnum",
Value: string(v),
Valid: []string{},
}
}
// The enum InterconnectAttachmentEncryptionEnum.
type InterconnectAttachmentEncryptionEnum string
// InterconnectAttachmentEncryptionEnumRef returns a *InterconnectAttachmentEncryptionEnum with the value of string s
// If the empty string is provided, nil is returned.
func InterconnectAttachmentEncryptionEnumRef(s string) *InterconnectAttachmentEncryptionEnum {
v := InterconnectAttachmentEncryptionEnum(s)
return &v
}
func (v InterconnectAttachmentEncryptionEnum) Validate() error {
if string(v) == "" {
// Empty enum is okay.
return nil
}
for _, s := range []string{"NONE", "IPSEC"} {
if string(v) == s {
return nil
}
}
return &dcl.EnumInvalidError{
Enum: "InterconnectAttachmentEncryptionEnum",
Value: string(v),
Valid: []string{},
}
}
type InterconnectAttachmentPrivateInterconnectInfo struct {
empty bool `json:"-"`
Tag8021q *int64 `json:"tag8021q"`
}
type jsonInterconnectAttachmentPrivateInterconnectInfo InterconnectAttachmentPrivateInterconnectInfo
func (r *InterconnectAttachmentPrivateInterconnectInfo) UnmarshalJSON(data []byte) error {
var res jsonInterconnectAttachmentPrivateInterconnectInfo
if err := json.Unmarshal(data, &res); err != nil {
return err
}
var m map[string]interface{}
json.Unmarshal(data, &m)
if len(m) == 0 {
*r = *EmptyInterconnectAttachmentPrivateInterconnectInfo
} else {
r.Tag8021q = res.Tag8021q
}
return nil
}
// This object is used to assert a desired state where this InterconnectAttachmentPrivateInterconnectInfo is
// empty. Go lacks global const objects, but this object should be treated
// as one. Modifying this object will have undesirable results.
var EmptyInterconnectAttachmentPrivateInterconnectInfo *InterconnectAttachmentPrivateInterconnectInfo = &InterconnectAttachmentPrivateInterconnectInfo{empty: true}
func (r *InterconnectAttachmentPrivateInterconnectInfo) Empty() bool {
return r.empty
}
func (r *InterconnectAttachmentPrivateInterconnectInfo) String() string {
return dcl.SprintResource(r)
}
func (r *InterconnectAttachmentPrivateInterconnectInfo) HashCode() string {
// Placeholder for a more complex hash method that handles ordering, etc
// Hash resource body for easy comparison later
hash := sha256.New().Sum([]byte(r.String()))
return fmt.Sprintf("%x", hash)
}
type InterconnectAttachmentPartnerMetadata struct {
empty bool `json:"-"`
PartnerName *string `json:"partnerName"`
InterconnectName *string `json:"interconnectName"`
PortalUrl *string `json:"portalUrl"`
}
type jsonInterconnectAttachmentPartnerMetadata InterconnectAttachmentPartnerMetadata
func (r *InterconnectAttachmentPartnerMetadata) UnmarshalJSON(data []byte) error {
var res jsonInterconnectAttachmentPartnerMetadata
if err := json.Unmarshal(data, &res); err != nil {
return err
}
var m map[string]interface{}
json.Unmarshal(data, &m)
if len(m) == 0 {
*r = *EmptyInterconnectAttachmentPartnerMetadata
} else {
r.PartnerName = res.PartnerName
r.InterconnectName = res.InterconnectName
r.PortalUrl = res.PortalUrl
}
return nil
}
// This object is used to assert a desired state where this InterconnectAttachmentPartnerMetadata is
// empty. Go lacks global const objects, but this object should be treated
// as one. Modifying this object will have undesirable results.
var EmptyInterconnectAttachmentPartnerMetadata *InterconnectAttachmentPartnerMetadata = &InterconnectAttachmentPartnerMetadata{empty: true}
func (r *InterconnectAttachmentPartnerMetadata) Empty() bool {
return r.empty
}
func (r *InterconnectAttachmentPartnerMetadata) String() string {
return dcl.SprintResource(r)
}
func (r *InterconnectAttachmentPartnerMetadata) HashCode() string {
// Placeholder for a more complex hash method that handles ordering, etc
// Hash resource body for easy comparison later
hash := sha256.New().Sum([]byte(r.String()))
return fmt.Sprintf("%x", hash)
}
// Describe returns a simple description of this resource to ensure that automated tools
// can identify it.
func (r *InterconnectAttachment) Describe() dcl.ServiceTypeVersion {
return dcl.ServiceTypeVersion{
Service: "compute",
Type: "InterconnectAttachment",
Version: "compute",
}
}
func (r *InterconnectAttachment) ID() (string, error) {
if err := extractInterconnectAttachmentFields(r); err != nil {
return "", err
}
nr := r.urlNormalized()
params := map[string]interface{}{
"description": dcl.ValueOrEmptyString(nr.Description),
"self_link": dcl.ValueOrEmptyString(nr.SelfLink),
"id": dcl.ValueOrEmptyString(nr.Id),
"name": dcl.ValueOrEmptyString(nr.Name),
"interconnect": dcl.ValueOrEmptyString(nr.Interconnect),
"router": dcl.ValueOrEmptyString(nr.Router),
"region": dcl.ValueOrEmptyString(nr.Region),
"mtu": dcl.ValueOrEmptyString(nr.Mtu),
"private_interconnect_info": dcl.ValueOrEmptyString(nr.PrivateInterconnectInfo),
"operational_status": dcl.ValueOrEmptyString(nr.OperationalStatus),
"cloud_router_ip_address": dcl.ValueOrEmptyString(nr.CloudRouterIPAddress),
"customer_router_ip_address": dcl.ValueOrEmptyString(nr.CustomerRouterIPAddress),
"type": dcl.ValueOrEmptyString(nr.Type),
"pairing_key": dcl.ValueOrEmptyString(nr.PairingKey),
"admin_enabled": dcl.ValueOrEmptyString(nr.AdminEnabled),
"vlan_tag8021q": dcl.ValueOrEmptyString(nr.VlanTag8021q),
"edge_availability_domain": dcl.ValueOrEmptyString(nr.EdgeAvailabilityDomain),
"candidate_subnets": dcl.ValueOrEmptyString(nr.CandidateSubnets),
"bandwidth": dcl.ValueOrEmptyString(nr.Bandwidth),
"partner_metadata": dcl.ValueOrEmptyString(nr.PartnerMetadata),
"state": dcl.ValueOrEmptyString(nr.State),
"partner_asn": dcl.ValueOrEmptyString(nr.PartnerAsn),
"encryption": dcl.ValueOrEmptyString(nr.Encryption),
"ipsec_internal_addresses": dcl.ValueOrEmptyString(nr.IpsecInternalAddresses),
"dataplane_version": dcl.ValueOrEmptyString(nr.DataplaneVersion),
"satisfies_pzs": dcl.ValueOrEmptyString(nr.SatisfiesPzs),
"project": dcl.ValueOrEmptyString(nr.Project),
}
return dcl.Nprintf("projects/{{project}}/regions/{{region}}/interconnectAttachments/{{name}}", params), nil
}
const InterconnectAttachmentMaxPage = -1
type InterconnectAttachmentList struct {
Items []*InterconnectAttachment
nextToken string
pageSize int32
resource *InterconnectAttachment
}
func (l *InterconnectAttachmentList) HasNext() bool {
return l.nextToken != ""
}
func (l *InterconnectAttachmentList) Next(ctx context.Context, c *Client) error {
ctx, cancel := context.WithTimeout(ctx, c.Config.TimeoutOr(0*time.Second))
defer cancel()
if !l.HasNext() {
return fmt.Errorf("no next page")
}
items, token, err := c.listInterconnectAttachment(ctx, l.resource, l.nextToken, l.pageSize)
if err != nil {
return err
}
l.Items = items
l.nextToken = token
return err
}
func (c *Client) ListInterconnectAttachment(ctx context.Context, project, region string) (*InterconnectAttachmentList, error) {
ctx = dcl.ContextWithRequestID(ctx)
ctx, cancel := context.WithTimeout(ctx, c.Config.TimeoutOr(0*time.Second))
defer cancel()
return c.ListInterconnectAttachmentWithMaxResults(ctx, project, region, InterconnectAttachmentMaxPage)
}
func (c *Client) ListInterconnectAttachmentWithMaxResults(ctx context.Context, project, region string, pageSize int32) (*InterconnectAttachmentList, error) {
ctx, cancel := context.WithTimeout(ctx, c.Config.TimeoutOr(0*time.Second))
defer cancel()
// Create a resource object so that we can use proper url normalization methods.
r := &InterconnectAttachment{
Project: &project,
Region: ®ion,
}
items, token, err := c.listInterconnectAttachment(ctx, r, "", pageSize)
if err != nil {
return nil, err
}
return &InterconnectAttachmentList{
Items: items,
nextToken: token,
pageSize: pageSize,
resource: r,
}, nil
}
func (c *Client) GetInterconnectAttachment(ctx context.Context, r *InterconnectAttachment) (*InterconnectAttachment, error) {
ctx = dcl.ContextWithRequestID(ctx)
ctx, cancel := context.WithTimeout(ctx, c.Config.TimeoutOr(0*time.Second))
defer cancel()
// This is *purposefully* supressing errors.
// This function is used with url-normalized values + not URL normalized values.
// URL Normalized values will throw unintentional errors, since those values are not of the proper parent form.
extractInterconnectAttachmentFields(r)
b, err := c.getInterconnectAttachmentRaw(ctx, r)
if err != nil {
if dcl.IsNotFound(err) {
return nil, &googleapi.Error{
Code: 404,
Message: err.Error(),
}
}
return nil, err
}
result, err := unmarshalInterconnectAttachment(b, c, r)
if err != nil {
return nil, err
}
result.Project = r.Project
result.Region = r.Region
result.Name = r.Name
c.Config.Logger.InfoWithContextf(ctx, "Retrieved raw result state: %v", result)
c.Config.Logger.InfoWithContextf(ctx, "Canonicalizing with specified state: %v", r)
result, err = canonicalizeInterconnectAttachmentNewState(c, result, r)
if err != nil {
return nil, err
}
if err := postReadExtractInterconnectAttachmentFields(result); err != nil {
return result, err
}
c.Config.Logger.InfoWithContextf(ctx, "Created result state: %v", result)
return result, nil
}
func (c *Client) DeleteInterconnectAttachment(ctx context.Context, r *InterconnectAttachment) error {
ctx = dcl.ContextWithRequestID(ctx)
ctx, cancel := context.WithTimeout(ctx, c.Config.TimeoutOr(0*time.Second))
defer cancel()
if r == nil {
return fmt.Errorf("InterconnectAttachment resource is nil")
}
c.Config.Logger.InfoWithContext(ctx, "Deleting InterconnectAttachment...")
deleteOp := deleteInterconnectAttachmentOperation{}
return deleteOp.do(ctx, r, c)
}
// DeleteAllInterconnectAttachment deletes all resources that the filter functions returns true on.
func (c *Client) DeleteAllInterconnectAttachment(ctx context.Context, project, region string, filter func(*InterconnectAttachment) bool) error {
listObj, err := c.ListInterconnectAttachment(ctx, project, region)
if err != nil {
return err
}
err = c.deleteAllInterconnectAttachment(ctx, filter, listObj.Items)
if err != nil {
return err
}
for listObj.HasNext() {
err = listObj.Next(ctx, c)
if err != nil {
return nil
}
err = c.deleteAllInterconnectAttachment(ctx, filter, listObj.Items)
if err != nil {
return err
}
}
return nil
}
func (c *Client) ApplyInterconnectAttachment(ctx context.Context, rawDesired *InterconnectAttachment, opts ...dcl.ApplyOption) (*InterconnectAttachment, error) {
ctx, cancel := context.WithTimeout(ctx, c.Config.TimeoutOr(0*time.Second))
defer cancel()
ctx = dcl.ContextWithRequestID(ctx)
var resultNewState *InterconnectAttachment
err := dcl.Do(ctx, func(ctx context.Context) (*dcl.RetryDetails, error) {
newState, err := applyInterconnectAttachmentHelper(c, ctx, rawDesired, opts...)
resultNewState = newState
if err != nil {
// If the error is 409, there is conflict in resource update.
// Here we want to apply changes based on latest state.
if dcl.IsConflictError(err) {
return &dcl.RetryDetails{}, dcl.OperationNotDone{Err: err}
}
return nil, err
}
return nil, nil
}, c.Config.RetryProvider)
return resultNewState, err
}
func applyInterconnectAttachmentHelper(c *Client, ctx context.Context, rawDesired *InterconnectAttachment, opts ...dcl.ApplyOption) (*InterconnectAttachment, error) {
c.Config.Logger.InfoWithContext(ctx, "Beginning ApplyInterconnectAttachment...")
c.Config.Logger.InfoWithContextf(ctx, "User specified desired state: %v", rawDesired)
// 1.1: Validation of user-specified fields in desired state.
if err := rawDesired.validate(); err != nil {
return nil, err
}
if err := extractInterconnectAttachmentFields(rawDesired); err != nil {
return nil, err
}
initial, desired, fieldDiffs, err := c.interconnectAttachmentDiffsForRawDesired(ctx, rawDesired, opts...)
if err != nil {
return nil, fmt.Errorf("failed to create a diff: %w", err)
}
diffs, err := convertFieldDiffsToInterconnectAttachmentDiffs(c.Config, fieldDiffs, opts)
if err != nil {
return nil, err
}
// TODO(magic-modules-eng): 2.2 Feasibility check (all updates are feasible so far).
// 2.3: Lifecycle Directive Check
var create bool
lp := dcl.FetchLifecycleParams(opts)
if initial == nil {
if dcl.HasLifecycleParam(lp, dcl.BlockCreation) {
return nil, dcl.ApplyInfeasibleError{Message: fmt.Sprintf("Creation blocked by lifecycle params: %#v.", desired)}
}
create = true
} else if dcl.HasLifecycleParam(lp, dcl.BlockAcquire) {
return nil, dcl.ApplyInfeasibleError{
Message: fmt.Sprintf("Resource already exists - apply blocked by lifecycle params: %#v.", initial),
}
} else {
for _, d := range diffs {
if d.RequiresRecreate {
return nil, dcl.ApplyInfeasibleError{
Message: fmt.Sprintf("infeasible update: (%v) would require recreation", d),
}
}
if dcl.HasLifecycleParam(lp, dcl.BlockModification) {
return nil, dcl.ApplyInfeasibleError{Message: fmt.Sprintf("Modification blocked, diff (%v) unresolvable.", d)}
}
}
}
// 2.4 Imperative Request Planning
var ops []interconnectAttachmentApiOperation
if create {
ops = append(ops, &createInterconnectAttachmentOperation{})
} else {
for _, d := range diffs {
ops = append(ops, d.UpdateOp)
}
}
c.Config.Logger.InfoWithContextf(ctx, "Created plan: %#v", ops)
// 2.5 Request Actuation
for _, op := range ops {
c.Config.Logger.InfoWithContextf(ctx, "Performing operation %T %+v", op, op)
if err := op.do(ctx, desired, c); err != nil {
c.Config.Logger.InfoWithContextf(ctx, "Failed operation %T %+v: %v", op, op, err)
return nil, err
}
c.Config.Logger.InfoWithContextf(ctx, "Finished operation %T %+v", op, op)
}
return applyInterconnectAttachmentDiff(c, ctx, desired, rawDesired, ops, opts...)
}
func applyInterconnectAttachmentDiff(c *Client, ctx context.Context, desired *InterconnectAttachment, rawDesired *InterconnectAttachment, ops []interconnectAttachmentApiOperation, opts ...dcl.ApplyOption) (*InterconnectAttachment, error) {
// 3.1, 3.2a Retrieval of raw new state & canonicalization with desired state
c.Config.Logger.InfoWithContext(ctx, "Retrieving raw new state...")
rawNew, err := c.GetInterconnectAttachment(ctx, desired)
if err != nil {
return nil, err
}
// Get additional values from the first response.
// These values should be merged into the newState above.
if len(ops) > 0 {
lastOp := ops[len(ops)-1]
if o, ok := lastOp.(*createInterconnectAttachmentOperation); ok {
if r, hasR := o.FirstResponse(); hasR {
c.Config.Logger.InfoWithContext(ctx, "Retrieving raw new state from operation...")
fullResp, err := unmarshalMapInterconnectAttachment(r, c, rawDesired)
if err != nil {
return nil, err
}
rawNew, err = canonicalizeInterconnectAttachmentNewState(c, rawNew, fullResp)
if err != nil {
return nil, err
}
}
}
}
c.Config.Logger.InfoWithContextf(ctx, "Canonicalizing with raw desired state: %v", rawDesired)
// 3.2b Canonicalization of raw new state using raw desired state
newState, err := canonicalizeInterconnectAttachmentNewState(c, rawNew, rawDesired)
if err != nil {
return rawNew, err
}
c.Config.Logger.InfoWithContextf(ctx, "Created canonical new state: %v", newState)
// 3.3 Comparison of the new state and raw desired state.
// TODO(magic-modules-eng): EVENTUALLY_CONSISTENT_UPDATE
newDesired, err := canonicalizeInterconnectAttachmentDesiredState(rawDesired, newState)
if err != nil {
return newState, err
}
if err := postReadExtractInterconnectAttachmentFields(newState); err != nil {
return newState, err
}
// Need to ensure any transformations made here match acceptably in differ.
if err := postReadExtractInterconnectAttachmentFields(newDesired); err != nil {
return newState, err
}
c.Config.Logger.InfoWithContextf(ctx, "Diffing using canonicalized desired state: %v", newDesired)
newDiffs, err := diffInterconnectAttachment(c, newDesired, newState)
if err != nil {
return newState, err
}
if len(newDiffs) == 0 {
c.Config.Logger.InfoWithContext(ctx, "No diffs found. Apply was successful.")
} else {
c.Config.Logger.InfoWithContextf(ctx, "Found diffs: %v", newDiffs)
diffMessages := make([]string, len(newDiffs))
for i, d := range newDiffs {
diffMessages[i] = fmt.Sprintf("%v", d)
}
return newState, dcl.DiffAfterApplyError{Diffs: diffMessages}
}
c.Config.Logger.InfoWithContext(ctx, "Done Apply.")
return newState, nil
}