Skip to content

Commit f559662

Browse files
Stefan KlasMaxrovr
authored andcommitted
Bug Fix - Api Gateway terraform correction to align with public sdk resource locking changes
1 parent d1ec57f commit f559662

File tree

7 files changed

+680
-0
lines changed

7 files changed

+680
-0
lines changed

examples/api_gateway/api/api.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ variable "api_display_name" {
2020
default = "test API definiton"
2121
}
2222

23+
variable "locks_type" {
24+
default = "DELETE"
25+
}
26+
27+
variable "locks_message" {
28+
default = "LockTest"
29+
}
30+
31+
variable "is_lock_override" {
32+
default = true
33+
}
34+
2335
provider "oci" {
2436
tenancy_ocid = var.tenancy_ocid
2537
user_ocid = var.user_ocid

internal/service/apigateway/apigateway_api_resource.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,42 @@ func ApigatewayApiResource() *schema.Resource {
6161
Computed: true,
6262
Elem: schema.TypeString,
6363
},
64+
"locks": {
65+
Type: schema.TypeList,
66+
Optional: true,
67+
Computed: true,
68+
Elem: &schema.Resource{
69+
Schema: map[string]*schema.Schema{
70+
// Required
71+
"type": {
72+
Type: schema.TypeString,
73+
Required: true,
74+
},
75+
76+
// Optional
77+
"message": {
78+
Type: schema.TypeString,
79+
Optional: true,
80+
Computed: true,
81+
},
82+
83+
// Computed
84+
"related_resource_id": {
85+
Type: schema.TypeString,
86+
Computed: true,
87+
},
88+
"time_created": {
89+
Type: schema.TypeString,
90+
Computed: true,
91+
},
92+
},
93+
},
94+
},
95+
"is_lock_override": {
96+
Type: schema.TypeBool,
97+
Optional: true,
98+
Computed: true,
99+
},
64100

65101
// Computed
66102
"lifecycle_details": {
@@ -75,6 +111,11 @@ func ApigatewayApiResource() *schema.Resource {
75111
Type: schema.TypeString,
76112
Computed: true,
77113
},
114+
"system_tags": {
115+
Type: schema.TypeMap,
116+
Computed: true,
117+
Elem: schema.TypeString,
118+
},
78119
"time_created": {
79120
Type: schema.TypeString,
80121
Computed: true,
@@ -210,6 +251,23 @@ func (s *ApigatewayApiResourceCrud) Create() error {
210251
request.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
211252
}
212253

254+
if locks, ok := s.D.GetOkExists("locks"); ok {
255+
interfaces := locks.([]interface{})
256+
tmp := make([]oci_apigateway.AddResourceLockDetails, len(interfaces))
257+
for i := range interfaces {
258+
stateDataIndex := i
259+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "locks", stateDataIndex)
260+
converted, err := s.mapToAddResourceLockDetails(fieldKeyFormat)
261+
if err != nil {
262+
return err
263+
}
264+
tmp[i] = converted
265+
}
266+
if len(tmp) != 0 || s.D.HasChange("locks") {
267+
request.Locks = tmp
268+
}
269+
}
270+
213271
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "apigateway")
214272

215273
response, err := s.Client.CreateApi(context.Background(), request)
@@ -409,6 +467,11 @@ func (s *ApigatewayApiResourceCrud) Update() error {
409467
request.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
410468
}
411469

470+
if isLockOverride, ok := s.D.GetOkExists("is_lock_override"); ok {
471+
tmp := isLockOverride.(bool)
472+
request.IsLockOverride = &tmp
473+
}
474+
412475
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "apigateway")
413476

414477
response, err := s.Client.UpdateApi(context.Background(), request)
@@ -430,6 +493,11 @@ func (s *ApigatewayApiResourceCrud) Delete() error {
430493
tmp := s.D.Id()
431494
request.ApiId = &tmp
432495

496+
if isLockOverride, ok := s.D.GetOkExists("is_lock_override"); ok {
497+
tmp := isLockOverride.(bool)
498+
request.IsLockOverride = &tmp
499+
}
500+
433501
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "apigateway")
434502

435503
response, err := s.Client.DeleteApi(context.Background(), request)
@@ -463,12 +531,22 @@ func (s *ApigatewayApiResourceCrud) SetData() error {
463531
s.D.Set("lifecycle_details", *s.Res.LifecycleDetails)
464532
}
465533

534+
locks := []interface{}{}
535+
for _, item := range s.Res.Locks {
536+
locks = append(locks, ResourceLockToMap(item))
537+
}
538+
s.D.Set("locks", locks)
539+
466540
if s.Res.SpecificationType != nil {
467541
s.D.Set("specification_type", *s.Res.SpecificationType)
468542
}
469543

470544
s.D.Set("state", s.Res.LifecycleState)
471545

546+
if s.Res.SystemTags != nil {
547+
s.D.Set("system_tags", tfresource.SystemTagsToMap(s.Res.SystemTags))
548+
}
549+
472550
if s.Res.TimeCreated != nil {
473551
s.D.Set("time_created", s.Res.TimeCreated.String())
474552
}
@@ -486,6 +564,21 @@ func (s *ApigatewayApiResourceCrud) SetData() error {
486564
return nil
487565
}
488566

567+
func (s *ApigatewayApiResourceCrud) mapToAddResourceLockDetails(fieldKeyFormat string) (oci_apigateway.AddResourceLockDetails, error) {
568+
result := oci_apigateway.AddResourceLockDetails{}
569+
570+
if message, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "message")); ok {
571+
tmp := message.(string)
572+
result.Message = &tmp
573+
}
574+
575+
if type_, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "type")); ok {
576+
result.Type = oci_apigateway.AddResourceLockDetailsTypeEnum(type_.(string))
577+
}
578+
579+
return result, nil
580+
}
581+
489582
func ApiSummaryToMap(obj oci_apigateway.ApiSummary) map[string]interface{} {
490583
result := map[string]interface{}{}
491584

@@ -511,12 +604,22 @@ func ApiSummaryToMap(obj oci_apigateway.ApiSummary) map[string]interface{} {
511604
result["lifecycle_details"] = string(*obj.LifecycleDetails)
512605
}
513606

607+
locks := []interface{}{}
608+
for _, item := range obj.Locks {
609+
locks = append(locks, ResourceLockToMap(item))
610+
}
611+
result["locks"] = locks
612+
514613
if obj.SpecificationType != nil {
515614
result["specification_type"] = string(*obj.SpecificationType)
516615
}
517616

518617
result["state"] = string(obj.LifecycleState)
519618

619+
if obj.SystemTags != nil {
620+
result["system_tags"] = tfresource.SystemTagsToMap(obj.SystemTags)
621+
}
622+
520623
if obj.TimeCreated != nil {
521624
result["time_created"] = obj.TimeCreated.String()
522625
}
@@ -555,6 +658,11 @@ func (s *ApigatewayApiResourceCrud) updateCompartment(compartment interface{}) e
555658
compartmentTmp := compartment.(string)
556659
changeCompartmentRequest.CompartmentId = &compartmentTmp
557660

661+
if isLockOverride, ok := s.D.GetOkExists("is_lock_override"); ok {
662+
tmp := isLockOverride.(bool)
663+
changeCompartmentRequest.IsLockOverride = &tmp
664+
}
665+
558666
changeCompartmentRequest.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "apigateway")
559667

560668
response, err := s.Client.ChangeApiCompartment(context.Background(), changeCompartmentRequest)

internal/service/apigateway/apigateway_certificate_resource.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,42 @@ func ApigatewayCertificateResource() *schema.Resource {
7373
Computed: true,
7474
ForceNew: true,
7575
},
76+
"locks": {
77+
Type: schema.TypeList,
78+
Optional: true,
79+
Computed: true,
80+
Elem: &schema.Resource{
81+
Schema: map[string]*schema.Schema{
82+
// Required
83+
"type": {
84+
Type: schema.TypeString,
85+
Required: true,
86+
},
87+
88+
// Optional
89+
"message": {
90+
Type: schema.TypeString,
91+
Optional: true,
92+
Computed: true,
93+
},
94+
95+
// Computed
96+
"related_resource_id": {
97+
Type: schema.TypeString,
98+
Computed: true,
99+
},
100+
"time_created": {
101+
Type: schema.TypeString,
102+
Computed: true,
103+
},
104+
},
105+
},
106+
},
107+
"is_lock_override": {
108+
Type: schema.TypeBool,
109+
Optional: true,
110+
Computed: true,
111+
},
76112

77113
// Computed
78114
"lifecycle_details": {
@@ -90,6 +126,11 @@ func ApigatewayCertificateResource() *schema.Resource {
90126
Type: schema.TypeString,
91127
},
92128
},
129+
"system_tags": {
130+
Type: schema.TypeMap,
131+
Computed: true,
132+
Elem: schema.TypeString,
133+
},
93134
"time_created": {
94135
Type: schema.TypeString,
95136
Computed: true,
@@ -213,6 +254,23 @@ func (s *ApigatewayCertificateResourceCrud) Create() error {
213254
request.IntermediateCertificates = &tmp
214255
}
215256

257+
if locks, ok := s.D.GetOkExists("locks"); ok {
258+
interfaces := locks.([]interface{})
259+
tmp := make([]oci_apigateway.AddResourceLockDetails, len(interfaces))
260+
for i := range interfaces {
261+
stateDataIndex := i
262+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "locks", stateDataIndex)
263+
converted, err := s.mapToAddResourceLockDetails(fieldKeyFormat)
264+
if err != nil {
265+
return err
266+
}
267+
tmp[i] = converted
268+
}
269+
if len(tmp) != 0 || s.D.HasChange("locks") {
270+
request.Locks = tmp
271+
}
272+
}
273+
216274
if privateKey, ok := s.D.GetOkExists("private_key"); ok {
217275
tmp := privateKey.(string)
218276
request.PrivateKey = &tmp
@@ -411,6 +469,11 @@ func (s *ApigatewayCertificateResourceCrud) Update() error {
411469
request.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
412470
}
413471

472+
if isLockOverride, ok := s.D.GetOkExists("is_lock_override"); ok {
473+
tmp := isLockOverride.(bool)
474+
request.IsLockOverride = &tmp
475+
}
476+
414477
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "apigateway")
415478

416479
response, err := s.Client.UpdateCertificate(context.Background(), request)
@@ -428,6 +491,11 @@ func (s *ApigatewayCertificateResourceCrud) Delete() error {
428491
tmp := s.D.Id()
429492
request.CertificateId = &tmp
430493

494+
if isLockOverride, ok := s.D.GetOkExists("is_lock_override"); ok {
495+
tmp := isLockOverride.(bool)
496+
request.IsLockOverride = &tmp
497+
}
498+
431499
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "apigateway")
432500

433501
_, err := s.Client.DeleteCertificate(context.Background(), request)
@@ -461,10 +529,20 @@ func (s *ApigatewayCertificateResourceCrud) SetData() error {
461529
s.D.Set("lifecycle_details", *s.Res.LifecycleDetails)
462530
}
463531

532+
locks := []interface{}{}
533+
for _, item := range s.Res.Locks {
534+
locks = append(locks, ResourceLockToMap(item))
535+
}
536+
s.D.Set("locks", locks)
537+
464538
s.D.Set("state", s.Res.LifecycleState)
465539

466540
s.D.Set("subject_names", s.Res.SubjectNames)
467541

542+
if s.Res.SystemTags != nil {
543+
s.D.Set("system_tags", tfresource.SystemTagsToMap(s.Res.SystemTags))
544+
}
545+
468546
if s.Res.TimeCreated != nil {
469547
s.D.Set("time_created", s.Res.TimeCreated.String())
470548
}
@@ -480,6 +558,21 @@ func (s *ApigatewayCertificateResourceCrud) SetData() error {
480558
return nil
481559
}
482560

561+
func (s *ApigatewayCertificateResourceCrud) mapToAddResourceLockDetails(fieldKeyFormat string) (oci_apigateway.AddResourceLockDetails, error) {
562+
result := oci_apigateway.AddResourceLockDetails{}
563+
564+
if message, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "message")); ok {
565+
tmp := message.(string)
566+
result.Message = &tmp
567+
}
568+
569+
if type_, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "type")); ok {
570+
result.Type = oci_apigateway.AddResourceLockDetailsTypeEnum(type_.(string))
571+
}
572+
573+
return result, nil
574+
}
575+
483576
func CertificateSummaryToMap(obj oci_apigateway.CertificateSummary) map[string]interface{} {
484577
result := map[string]interface{}{}
485578

@@ -505,10 +598,20 @@ func CertificateSummaryToMap(obj oci_apigateway.CertificateSummary) map[string]i
505598
result["lifecycle_details"] = string(*obj.LifecycleDetails)
506599
}
507600

601+
locks := []interface{}{}
602+
for _, item := range obj.Locks {
603+
locks = append(locks, ResourceLockToMap(item))
604+
}
605+
result["locks"] = locks
606+
508607
result["state"] = string(obj.LifecycleState)
509608

510609
result["subject_names"] = obj.SubjectNames
511610

611+
if obj.SystemTags != nil {
612+
result["system_tags"] = tfresource.SystemTagsToMap(obj.SystemTags)
613+
}
614+
512615
if obj.TimeCreated != nil {
513616
result["time_created"] = obj.TimeCreated.String()
514617
}
@@ -533,6 +636,11 @@ func (s *ApigatewayCertificateResourceCrud) updateCompartment(compartment interf
533636
compartmentTmp := compartment.(string)
534637
changeCompartmentRequest.CompartmentId = &compartmentTmp
535638

639+
if isLockOverride, ok := s.D.GetOkExists("is_lock_override"); ok {
640+
tmp := isLockOverride.(bool)
641+
changeCompartmentRequest.IsLockOverride = &tmp
642+
}
643+
536644
changeCompartmentRequest.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "apigateway")
537645

538646
_, err := s.Client.ChangeCertificateCompartment(context.Background(), changeCompartmentRequest)

0 commit comments

Comments
 (0)