|
3 | 3 | package provider |
4 | 4 |
|
5 | 5 | import ( |
6 | | - "bytes" |
7 | 6 | "context" |
8 | | - "fmt" |
9 | 7 |
|
10 | | - "github.com/hashicorp/terraform/helper/hashcode" |
11 | 8 | "github.com/hashicorp/terraform/helper/schema" |
12 | 9 |
|
13 | 10 | oci_core "github.com/oracle/oci-go-sdk/core" |
@@ -77,77 +74,6 @@ func CoreIpSecConnectionResource() *schema.Resource { |
77 | 74 | Computed: true, |
78 | 75 | Elem: schema.TypeString, |
79 | 76 | }, |
80 | | - "tunnel_configuration": { |
81 | | - Type: schema.TypeSet, |
82 | | - Optional: true, |
83 | | - Computed: true, |
84 | | - ForceNew: true, |
85 | | - MaxItems: 2, |
86 | | - MinItems: 1, |
87 | | - Set: tunnelConfigurationHashCodeForSets, |
88 | | - Elem: &schema.Resource{ |
89 | | - Schema: map[string]*schema.Schema{ |
90 | | - // Required |
91 | | - |
92 | | - // Optional |
93 | | - "bgp_session_config": { |
94 | | - Type: schema.TypeList, |
95 | | - Optional: true, |
96 | | - Computed: true, |
97 | | - ForceNew: true, |
98 | | - MaxItems: 1, |
99 | | - MinItems: 1, |
100 | | - Elem: &schema.Resource{ |
101 | | - Schema: map[string]*schema.Schema{ |
102 | | - // Required |
103 | | - |
104 | | - // Optional |
105 | | - "customer_bgp_asn": { |
106 | | - Type: schema.TypeString, |
107 | | - Optional: true, |
108 | | - Computed: true, |
109 | | - ForceNew: true, |
110 | | - }, |
111 | | - "customer_interface_ip": { |
112 | | - Type: schema.TypeString, |
113 | | - Optional: true, |
114 | | - Computed: true, |
115 | | - ForceNew: true, |
116 | | - }, |
117 | | - "oracle_interface_ip": { |
118 | | - Type: schema.TypeString, |
119 | | - Optional: true, |
120 | | - Computed: true, |
121 | | - ForceNew: true, |
122 | | - }, |
123 | | - |
124 | | - // Computed |
125 | | - }, |
126 | | - }, |
127 | | - }, |
128 | | - "display_name": { |
129 | | - Type: schema.TypeString, |
130 | | - Optional: true, |
131 | | - Computed: true, |
132 | | - ForceNew: true, |
133 | | - }, |
134 | | - "routing": { |
135 | | - Type: schema.TypeString, |
136 | | - Optional: true, |
137 | | - Computed: true, |
138 | | - ForceNew: true, |
139 | | - }, |
140 | | - "shared_secret": { |
141 | | - Type: schema.TypeString, |
142 | | - Optional: true, |
143 | | - Computed: true, |
144 | | - ForceNew: true, |
145 | | - }, |
146 | | - |
147 | | - // Computed |
148 | | - }, |
149 | | - }, |
150 | | - }, |
151 | 77 |
|
152 | 78 | // Computed |
153 | 79 | "state": { |
@@ -218,6 +144,18 @@ func (s *CoreIpSecConnectionResourceCrud) CreatedTarget() []string { |
218 | 144 | } |
219 | 145 | } |
220 | 146 |
|
| 147 | +func (s *CoreIpSecConnectionResourceCrud) UpdatedPending() []string { |
| 148 | + return []string{ |
| 149 | + string(oci_core.IpSecConnectionLifecycleStateProvisioning), |
| 150 | + } |
| 151 | +} |
| 152 | + |
| 153 | +func (s *CoreIpSecConnectionResourceCrud) UpdatedTarget() []string { |
| 154 | + return []string{ |
| 155 | + string(oci_core.IpSecConnectionLifecycleStateAvailable), |
| 156 | + } |
| 157 | +} |
| 158 | + |
221 | 159 | func (s *CoreIpSecConnectionResourceCrud) DeletedPending() []string { |
222 | 160 | return []string{ |
223 | 161 | string(oci_core.IpSecConnectionLifecycleStateTerminating), |
@@ -286,22 +224,6 @@ func (s *CoreIpSecConnectionResourceCrud) Create() error { |
286 | 224 | request.StaticRoutes = tmp |
287 | 225 | } |
288 | 226 |
|
289 | | - if tunnelConfiguration, ok := s.D.GetOkExists("tunnel_configuration"); ok { |
290 | | - set := tunnelConfiguration.(*schema.Set) |
291 | | - interfaces := set.List() |
292 | | - tmp := make([]oci_core.CreateIpSecConnectionTunnelDetails, len(interfaces)) |
293 | | - for i := range interfaces { |
294 | | - stateDataIndex := tunnelConfigurationHashCodeForSets(interfaces[i]) |
295 | | - fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "tunnel_configuration", stateDataIndex) |
296 | | - converted, err := s.mapToCreateIPSecConnectionTunnelDetails(fieldKeyFormat) |
297 | | - if err != nil { |
298 | | - return err |
299 | | - } |
300 | | - tmp[i] = converted |
301 | | - } |
302 | | - request.TunnelConfiguration = tmp |
303 | | - } |
304 | | - |
305 | 227 | request.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "core") |
306 | 228 |
|
307 | 229 | response, err := s.Client.CreateIPSecConnection(context.Background(), request) |
@@ -436,123 +358,3 @@ func (s *CoreIpSecConnectionResourceCrud) SetData() error { |
436 | 358 |
|
437 | 359 | return nil |
438 | 360 | } |
439 | | - |
440 | | -func (s *CoreIpSecConnectionResourceCrud) mapToCreateIPSecConnectionTunnelDetails(fieldKeyFormat string) (oci_core.CreateIpSecConnectionTunnelDetails, error) { |
441 | | - result := oci_core.CreateIpSecConnectionTunnelDetails{} |
442 | | - |
443 | | - if bgpSessionConfig, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "bgp_session_config")); ok { |
444 | | - if tmpList := bgpSessionConfig.([]interface{}); len(tmpList) > 0 { |
445 | | - fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "bgp_session_config"), 0) |
446 | | - tmp, err := s.mapToCreateIPSecTunnelBgpSessionDetails(fieldKeyFormatNextLevel) |
447 | | - if err != nil { |
448 | | - return result, fmt.Errorf("unable to convert bgp_session_config, encountered error: %v", err) |
449 | | - } |
450 | | - result.BgpSessionConfig = &tmp |
451 | | - } |
452 | | - } |
453 | | - |
454 | | - if displayName, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "display_name")); ok { |
455 | | - tmp := displayName.(string) |
456 | | - result.DisplayName = &tmp |
457 | | - } |
458 | | - |
459 | | - if routing, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "routing")); ok { |
460 | | - result.Routing = oci_core.CreateIpSecConnectionTunnelDetailsRoutingEnum(routing.(string)) |
461 | | - } |
462 | | - |
463 | | - if sharedSecret, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "shared_secret")); ok { |
464 | | - tmp := sharedSecret.(string) |
465 | | - result.SharedSecret = &tmp |
466 | | - } |
467 | | - |
468 | | - return result, nil |
469 | | -} |
470 | | - |
471 | | -func CreateIPSecConnectionTunnelDetailsToMap(obj oci_core.CreateIpSecConnectionTunnelDetails) map[string]interface{} { |
472 | | - result := map[string]interface{}{} |
473 | | - |
474 | | - if obj.BgpSessionConfig != nil { |
475 | | - result["bgp_session_config"] = []interface{}{CreateIPSecTunnelBgpSessionDetailsToMap(obj.BgpSessionConfig)} |
476 | | - } |
477 | | - |
478 | | - if obj.DisplayName != nil { |
479 | | - result["display_name"] = string(*obj.DisplayName) |
480 | | - } |
481 | | - |
482 | | - result["routing"] = string(obj.Routing) |
483 | | - |
484 | | - if obj.SharedSecret != nil { |
485 | | - result["shared_secret"] = string(*obj.SharedSecret) |
486 | | - } |
487 | | - |
488 | | - return result |
489 | | -} |
490 | | - |
491 | | -func (s *CoreIpSecConnectionResourceCrud) mapToCreateIPSecTunnelBgpSessionDetails(fieldKeyFormat string) (oci_core.CreateIpSecTunnelBgpSessionDetails, error) { |
492 | | - result := oci_core.CreateIpSecTunnelBgpSessionDetails{} |
493 | | - |
494 | | - if customerBgpAsn, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "customer_bgp_asn")); ok { |
495 | | - tmp := customerBgpAsn.(string) |
496 | | - result.CustomerBgpAsn = &tmp |
497 | | - } |
498 | | - |
499 | | - if customerInterfaceIp, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "customer_interface_ip")); ok { |
500 | | - tmp := customerInterfaceIp.(string) |
501 | | - result.CustomerInterfaceIp = &tmp |
502 | | - } |
503 | | - |
504 | | - if oracleInterfaceIp, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "oracle_interface_ip")); ok { |
505 | | - tmp := oracleInterfaceIp.(string) |
506 | | - result.OracleInterfaceIp = &tmp |
507 | | - } |
508 | | - |
509 | | - return result, nil |
510 | | -} |
511 | | - |
512 | | -func CreateIPSecTunnelBgpSessionDetailsToMap(obj *oci_core.CreateIpSecTunnelBgpSessionDetails) map[string]interface{} { |
513 | | - result := map[string]interface{}{} |
514 | | - |
515 | | - if obj.CustomerBgpAsn != nil { |
516 | | - result["customer_bgp_asn"] = string(*obj.CustomerBgpAsn) |
517 | | - } |
518 | | - |
519 | | - if obj.CustomerInterfaceIp != nil { |
520 | | - result["customer_interface_ip"] = string(*obj.CustomerInterfaceIp) |
521 | | - } |
522 | | - |
523 | | - if obj.OracleInterfaceIp != nil { |
524 | | - result["oracle_interface_ip"] = string(*obj.OracleInterfaceIp) |
525 | | - } |
526 | | - |
527 | | - return result |
528 | | -} |
529 | | - |
530 | | -func tunnelConfigurationHashCodeForSets(v interface{}) int { |
531 | | - var buf bytes.Buffer |
532 | | - m := v.(map[string]interface{}) |
533 | | - if bgpSessionConfig, ok := m["bgp_session_config"]; ok { |
534 | | - if tmpList := bgpSessionConfig.([]interface{}); len(tmpList) > 0 { |
535 | | - buf.WriteString("bgp_session_config-") |
536 | | - bgpSessionConfigRaw := tmpList[0].(map[string]interface{}) |
537 | | - if customerBgpAsn, ok := bgpSessionConfigRaw["customer_bgp_asn"]; ok && customerBgpAsn != "" { |
538 | | - buf.WriteString(fmt.Sprintf("%v-", customerBgpAsn)) |
539 | | - } |
540 | | - if customerInterfaceIp, ok := bgpSessionConfigRaw["customer_interface_ip"]; ok && customerInterfaceIp != "" { |
541 | | - buf.WriteString(fmt.Sprintf("%v-", customerInterfaceIp)) |
542 | | - } |
543 | | - if oracleInterfaceIp, ok := bgpSessionConfigRaw["oracle_interface_ip"]; ok && oracleInterfaceIp != "" { |
544 | | - buf.WriteString(fmt.Sprintf("%v-", oracleInterfaceIp)) |
545 | | - } |
546 | | - } |
547 | | - } |
548 | | - if displayName, ok := m["display_name"]; ok && displayName != "" { |
549 | | - buf.WriteString(fmt.Sprintf("%v-", displayName)) |
550 | | - } |
551 | | - if routing, ok := m["routing"]; ok && routing != "" { |
552 | | - buf.WriteString(fmt.Sprintf("%v-", routing)) |
553 | | - } |
554 | | - if sharedSecret, ok := m["shared_secret"]; ok && sharedSecret != "" { |
555 | | - buf.WriteString(fmt.Sprintf("%v-", sharedSecret)) |
556 | | - } |
557 | | - return hashcode.String(buf.String()) |
558 | | -} |
0 commit comments