Skip to content

Commit 89d4a30

Browse files
authored
Merge pull request #787 from terraform-providers/v.3.28.2-hotfix
fix `oci_core_ipsec` backward compatibility issue
2 parents 6a59833 + d2d791b commit 89d4a30

13 files changed

+637
-326
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
## 3.28.2 (Unreleased)
1+
## 3.28.2 (June 07, 2019)
2+
3+
### Added
4+
- `oci_core_ipsec_connection_tunnel_management` resource to manage IPSec tunnel connection
5+
### Fixed
6+
- `oci_core_ipsec` backward compatibility issue by removing `tunnel_configuration` property, which is reported by https://github.com/terraform-providers/terraform-provider-oci/issues/779
7+
28
## 3.28.1 (June 05, 2019)
39

410
## Notes

examples/networking/ipsec_connections/ipsec_connection.tf

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,6 @@ resource "oci_core_ipsec" "test_ip_sec_connection" {
7373
defined_tags = "${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "${var.ip_sec_connection_defined_tags_value}")}"
7474
display_name = "${var.ip_sec_connection_display_name}"
7575
freeform_tags = "${var.ip_sec_connection_freeform_tags}"
76-
77-
tunnel_configuration {
78-
#Optional
79-
bgp_session_config {
80-
#Optional
81-
customer_bgp_asn = "${var.ip_sec_connection_tunnel_configuration_bgp_session_config_customer_bgp_asn}"
82-
customer_interface_ip = "${var.ip_sec_connection_tunnel_configuration_bgp_session_config_customer_interface_ip}"
83-
oracle_interface_ip = "${var.ip_sec_connection_tunnel_configuration_bgp_session_config_oracle_interface_ip}"
84-
}
85-
86-
display_name = "${var.ip_sec_connection_tunnel_configuration_display_name}"
87-
routing = "${var.ip_sec_connection_tunnel_configuration_routing}"
88-
shared_secret = "${var.ip_sec_connection_tunnel_configuration_shared_secret}"
89-
}
9076
}
9177

9278
data "oci_core_ipsec_connections" "test_ip_sec_connections" {
@@ -100,11 +86,25 @@ data "oci_core_ipsec_connections" "test_ip_sec_connections" {
10086

10187
data "oci_core_ipsec_connection_tunnels" "test_ip_sec_connection_tunnels" {
10288
ipsec_id = "${oci_core_ipsec.test_ip_sec_connection.id}"
103-
104-
# tunnel_id = ""
10589
}
10690

10791
data "oci_core_ipsec_connection_tunnel" "test_ipsec_connection_tunnel" {
10892
ipsec_id = "${oci_core_ipsec.test_ip_sec_connection.id}"
10993
tunnel_id = "${data.oci_core_ipsec_connection_tunnels.test_ip_sec_connection_tunnels.ip_sec_connection_tunnels.0.id}"
11094
}
95+
96+
resource "oci_core_ipsec_connection_tunnel_management" "test_ipsec_connection_tunnel_management" {
97+
ipsec_id = "${oci_core_ipsec.test_ip_sec_connection.id}"
98+
tunnel_id = "${data.oci_core_ipsec_connection_tunnels.test_ip_sec_connection_tunnels.ip_sec_connection_tunnels.0.id}"
99+
100+
#Optional
101+
bgp_session_info {
102+
customer_bgp_asn = "${var.ip_sec_connection_tunnel_configuration_bgp_session_config_customer_bgp_asn}"
103+
customer_interface_ip = "${var.ip_sec_connection_tunnel_configuration_bgp_session_config_customer_interface_ip}"
104+
oracle_interface_ip = "${var.ip_sec_connection_tunnel_configuration_bgp_session_config_oracle_interface_ip}"
105+
}
106+
107+
display_name = "${var.ip_sec_connection_tunnel_configuration_display_name}"
108+
routing = "${var.ip_sec_connection_tunnel_configuration_routing}"
109+
shared_secret = "${var.ip_sec_connection_tunnel_configuration_shared_secret}"
110+
}

oci/core_ip_sec_connection_resource.go

Lines changed: 12 additions & 210 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
package provider
44

55
import (
6-
"bytes"
76
"context"
8-
"fmt"
97

10-
"github.com/hashicorp/terraform/helper/hashcode"
118
"github.com/hashicorp/terraform/helper/schema"
129

1310
oci_core "github.com/oracle/oci-go-sdk/core"
@@ -77,77 +74,6 @@ func CoreIpSecConnectionResource() *schema.Resource {
7774
Computed: true,
7875
Elem: schema.TypeString,
7976
},
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-
},
15177

15278
// Computed
15379
"state": {
@@ -218,6 +144,18 @@ func (s *CoreIpSecConnectionResourceCrud) CreatedTarget() []string {
218144
}
219145
}
220146

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+
221159
func (s *CoreIpSecConnectionResourceCrud) DeletedPending() []string {
222160
return []string{
223161
string(oci_core.IpSecConnectionLifecycleStateTerminating),
@@ -286,22 +224,6 @@ func (s *CoreIpSecConnectionResourceCrud) Create() error {
286224
request.StaticRoutes = tmp
287225
}
288226

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-
305227
request.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "core")
306228

307229
response, err := s.Client.CreateIPSecConnection(context.Background(), request)
@@ -436,123 +358,3 @@ func (s *CoreIpSecConnectionResourceCrud) SetData() error {
436358

437359
return nil
438360
}
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-
}

oci/core_ip_sec_connection_test.go

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,6 @@ var (
4444
"defined_tags": Representation{repType: Optional, create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
4545
"display_name": Representation{repType: Optional, create: `MyIPSecConnection`, update: `displayName2`},
4646
"freeform_tags": Representation{repType: Optional, create: map[string]string{"Department": "Finance"}, update: map[string]string{"Department": "Accounting"}},
47-
"tunnel_configuration": RepresentationGroup{Optional, ipSecConnectionTunnelConfigurationRepresentation},
48-
}
49-
ipSecConnectionTunnelConfigurationRepresentation = map[string]interface{}{
50-
"bgp_session_config": RepresentationGroup{Optional, ipSecConnectionTunnelConfigurationBgpSessionConfigRepresentation},
51-
"display_name": Representation{repType: Optional, create: `MyIPSecConnection`},
52-
"routing": Representation{repType: Optional, create: `BGP`},
53-
"shared_secret": Representation{repType: Optional, create: `sharedSecret`},
54-
}
55-
ipSecConnectionTunnelConfigurationBgpSessionConfigRepresentation = map[string]interface{}{
56-
"customer_bgp_asn": Representation{repType: Optional, create: `1587232876`},
57-
"customer_interface_ip": Representation{repType: Optional, create: `10.0.0.16/31`},
58-
"oracle_interface_ip": Representation{repType: Optional, create: `10.0.0.17/31`},
5947
}
6048

6149
IpSecConnectionResourceDependencies = CpeRequiredOnlyResource + DrgRequiredOnlyResource
@@ -120,18 +108,6 @@ func TestCoreIpSecConnectionResource_basic(t *testing.T) {
120108
resource.TestCheckResourceAttrSet(resourceName, "id"),
121109
resource.TestCheckResourceAttrSet(resourceName, "state"),
122110
resource.TestCheckResourceAttr(resourceName, "static_routes.#", "1"),
123-
resource.TestCheckResourceAttr(resourceName, "tunnel_configuration.#", "1"),
124-
CheckResourceSetContainsElementWithProperties(resourceName, "tunnel_configuration", map[string]string{
125-
"bgp_session_config.#": "1",
126-
"display_name": "MyIPSecConnection",
127-
"routing": "BGP",
128-
"shared_secret": "sharedSecret",
129-
},
130-
[]string{
131-
"display_name",
132-
"routing",
133-
"shared_secret",
134-
}),
135111

136112
func(s *terraform.State) (err error) {
137113
resId, err = fromInstanceState(s, resourceName, "id")
@@ -156,18 +132,6 @@ func TestCoreIpSecConnectionResource_basic(t *testing.T) {
156132
resource.TestCheckResourceAttrSet(resourceName, "id"),
157133
resource.TestCheckResourceAttrSet(resourceName, "state"),
158134
resource.TestCheckResourceAttr(resourceName, "static_routes.#", "1"),
159-
resource.TestCheckResourceAttr(resourceName, "tunnel_configuration.#", "1"),
160-
CheckResourceSetContainsElementWithProperties(resourceName, "tunnel_configuration", map[string]string{
161-
"bgp_session_config.#": "1",
162-
"display_name": "MyIPSecConnection",
163-
"routing": "BGP",
164-
"shared_secret": "sharedSecret",
165-
},
166-
[]string{
167-
"display_name",
168-
"routing",
169-
"shared_secret",
170-
}),
171135

172136
func(s *terraform.State) (err error) {
173137
resId2, err = fromInstanceState(s, resourceName, "id")
@@ -206,13 +170,11 @@ func TestCoreIpSecConnectionResource_basic(t *testing.T) {
206170
},
207171
// verify resource import
208172
{
209-
Config: config,
210-
ImportState: true,
211-
ImportStateVerify: true,
212-
ImportStateVerifyIgnore: []string{
213-
"tunnel_configuration",
214-
},
215-
ResourceName: resourceName,
173+
Config: config,
174+
ImportState: true,
175+
ImportStateVerify: true,
176+
ImportStateVerifyIgnore: []string{},
177+
ResourceName: resourceName,
216178
},
217179
},
218180
})

0 commit comments

Comments
 (0)