Skip to content

Commit af0d10b

Browse files
committed
Support CPE device shape
1 parent f638d40 commit af0d10b

16 files changed

+537
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Added
44
- Support for updating `shape` attribute in `oci_database_db_system` resource
5+
- Support for CPE builder on IPSec console
56

67
## 3.64.0 (February 26, 2020)
78

examples/networking/ipsec_connections/ipsec_connection.tf

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,23 @@ provider "oci" {
1717
}
1818

1919
resource oci_core_cpe "test_cpe" {
20-
compartment_id = "${var.compartment_ocid}"
21-
display_name = "test_cpe"
22-
ip_address = "189.44.2.135"
20+
compartment_id = "${var.compartment_ocid}"
21+
display_name = "test_cpe"
22+
ip_address = "189.44.2.135"
23+
cpe_device_shape_id = "${data.oci_core_cpe_device_shape.test_cpe_device_shape.id}"
2324
}
2425

2526
resource oci_core_drg "test_drg" {
2627
compartment_id = "${var.compartment_ocid}"
2728
display_name = "test_drg"
2829
}
2930

31+
data "oci_core_cpe_device_shapes" "test_cpe_device_shapes" {}
32+
33+
data "oci_core_cpe_device_shape" "test_cpe_device_shape" {
34+
cpe_device_shape_id = "${data.oci_core_cpe_device_shapes.test_cpe_device_shapes.cpe_device_shapes.0.cpe_device_shape_id}"
35+
}
36+
3037
resource "oci_core_ipsec" "test_ip_sec_connection" {
3138
#Required
3239
compartment_id = "${var.compartment_ocid}"
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
// Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
2+
3+
package oci
4+
5+
import (
6+
"context"
7+
8+
"github.com/hashicorp/terraform/helper/schema"
9+
oci_core "github.com/oracle/oci-go-sdk/core"
10+
)
11+
12+
func CoreCpeDeviceShapeDataSource() *schema.Resource {
13+
return &schema.Resource{
14+
Read: readSingularCoreCpeDeviceShape,
15+
Schema: map[string]*schema.Schema{
16+
"cpe_device_shape_id": {
17+
Type: schema.TypeString,
18+
Required: true,
19+
},
20+
// Computed
21+
"cpe_device_info": {
22+
Type: schema.TypeList,
23+
Computed: true,
24+
Elem: &schema.Resource{
25+
Schema: map[string]*schema.Schema{
26+
// Required
27+
28+
// Optional
29+
30+
// Computed
31+
"platform_software_version": {
32+
Type: schema.TypeString,
33+
Computed: true,
34+
},
35+
"vendor": {
36+
Type: schema.TypeString,
37+
Computed: true,
38+
},
39+
},
40+
},
41+
},
42+
"parameters": {
43+
Type: schema.TypeList,
44+
Computed: true,
45+
Elem: &schema.Resource{
46+
Schema: map[string]*schema.Schema{
47+
// Required
48+
49+
// Optional
50+
51+
// Computed
52+
"display_name": {
53+
Type: schema.TypeString,
54+
Computed: true,
55+
},
56+
"explanation": {
57+
Type: schema.TypeString,
58+
Computed: true,
59+
},
60+
"key": {
61+
Type: schema.TypeString,
62+
Computed: true,
63+
},
64+
},
65+
},
66+
},
67+
"template": {
68+
Type: schema.TypeString,
69+
Computed: true,
70+
},
71+
},
72+
}
73+
}
74+
75+
func readSingularCoreCpeDeviceShape(d *schema.ResourceData, m interface{}) error {
76+
sync := &CoreCpeDeviceShapeDataSourceCrud{}
77+
sync.D = d
78+
sync.Client = m.(*OracleClients).virtualNetworkClient
79+
80+
return ReadResource(sync)
81+
}
82+
83+
type CoreCpeDeviceShapeDataSourceCrud struct {
84+
D *schema.ResourceData
85+
Client *oci_core.VirtualNetworkClient
86+
Res *oci_core.GetCpeDeviceShapeResponse
87+
}
88+
89+
func (s *CoreCpeDeviceShapeDataSourceCrud) VoidState() {
90+
s.D.SetId("")
91+
}
92+
93+
func (s *CoreCpeDeviceShapeDataSourceCrud) Get() error {
94+
request := oci_core.GetCpeDeviceShapeRequest{}
95+
96+
if cpeDeviceShapeId, ok := s.D.GetOkExists("cpe_device_shape_id"); ok {
97+
tmp := cpeDeviceShapeId.(string)
98+
request.CpeDeviceShapeId = &tmp
99+
}
100+
101+
request.RequestMetadata.RetryPolicy = getRetryPolicy(false, "core")
102+
103+
response, err := s.Client.GetCpeDeviceShape(context.Background(), request)
104+
if err != nil {
105+
return err
106+
}
107+
108+
s.Res = &response
109+
return nil
110+
}
111+
112+
func (s *CoreCpeDeviceShapeDataSourceCrud) SetData() error {
113+
if s.Res == nil {
114+
return nil
115+
}
116+
117+
s.D.SetId(*s.Res.CpeDeviceShapeId)
118+
119+
if s.Res.CpeDeviceInfo != nil {
120+
s.D.Set("cpe_device_info", []interface{}{CpeDeviceInfoToMap(s.Res.CpeDeviceInfo)})
121+
} else {
122+
s.D.Set("cpe_device_info", nil)
123+
}
124+
125+
parameters := []interface{}{}
126+
for _, item := range s.Res.Parameters {
127+
parameters = append(parameters, CpeDeviceConfigQuestionToMap(item))
128+
}
129+
s.D.Set("parameters", parameters)
130+
131+
if s.Res.Template != nil {
132+
s.D.Set("template", *s.Res.Template)
133+
}
134+
135+
return nil
136+
}
137+
138+
func CpeDeviceConfigQuestionToMap(obj oci_core.CpeDeviceConfigQuestion) map[string]interface{} {
139+
result := map[string]interface{}{}
140+
141+
if obj.DisplayName != nil {
142+
result["display_name"] = string(*obj.DisplayName)
143+
}
144+
145+
if obj.Explanation != nil {
146+
result["explanation"] = string(*obj.Explanation)
147+
}
148+
149+
if obj.Key != nil {
150+
result["key"] = string(*obj.Key)
151+
}
152+
153+
return result
154+
}
155+
156+
func CpeDeviceInfoToMap(obj *oci_core.CpeDeviceInfo) map[string]interface{} {
157+
result := map[string]interface{}{}
158+
159+
if obj.PlatformSoftwareVersion != nil {
160+
result["platform_software_version"] = string(*obj.PlatformSoftwareVersion)
161+
}
162+
163+
if obj.Vendor != nil {
164+
result["vendor"] = string(*obj.Vendor)
165+
}
166+
167+
return result
168+
}

oci/core_cpe_device_shape_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
2+
3+
package oci
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform/helper/resource"
10+
"github.com/hashicorp/terraform/terraform"
11+
12+
"github.com/terraform-providers/terraform-provider-oci/httpreplay"
13+
)
14+
15+
var (
16+
cpeDeviceShapeSingularDataSourceRepresentation = map[string]interface{}{
17+
"cpe_device_shape_id": Representation{repType: Required, create: `${data.oci_core_cpe_device_shapes.test_cpe_device_shapes.cpe_device_shapes.0.cpe_device_shape_id}`},
18+
}
19+
20+
cpeDeviceShapeDataSourceRepresentation = map[string]interface{}{}
21+
22+
CpeDeviceShapeResourceConfig = ""
23+
)
24+
25+
func TestCoreCpeDeviceShapeResource_basic(t *testing.T) {
26+
httpreplay.SetScenario("TestCoreCpeDeviceShapeResource_basic")
27+
defer httpreplay.SaveScenario()
28+
29+
provider := testAccProvider
30+
config := testProviderConfig()
31+
32+
compartmentId := getEnvSettingWithBlankDefault("compartment_ocid")
33+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
34+
35+
datasourceName := "data.oci_core_cpe_device_shapes.test_cpe_device_shapes"
36+
singularDatasourceName := "data.oci_core_cpe_device_shape.test_cpe_device_shape"
37+
38+
resource.Test(t, resource.TestCase{
39+
PreCheck: func() { testAccPreCheck(t) },
40+
Providers: map[string]terraform.ResourceProvider{
41+
"oci": provider,
42+
},
43+
Steps: []resource.TestStep{
44+
// verify datasource
45+
{
46+
Config: config +
47+
generateDataSourceFromRepresentationMap("oci_core_cpe_device_shapes", "test_cpe_device_shapes", Required, Create, cpeDeviceShapeDataSourceRepresentation) +
48+
compartmentIdVariableStr + CpeDeviceShapeResourceConfig,
49+
Check: resource.ComposeAggregateTestCheckFunc(
50+
51+
resource.TestCheckResourceAttrSet(datasourceName, "cpe_device_shapes.#"),
52+
resource.TestCheckResourceAttr(datasourceName, "cpe_device_shapes.0.cpe_device_info.#", "1"),
53+
),
54+
},
55+
// verify singular datasource
56+
{
57+
Config: config +
58+
generateDataSourceFromRepresentationMap("oci_core_cpe_device_shape", "test_cpe_device_shape", Required, Create, cpeDeviceShapeSingularDataSourceRepresentation) +
59+
generateDataSourceFromRepresentationMap("oci_core_cpe_device_shapes", "test_cpe_device_shapes", Required, Create, cpeDeviceShapeDataSourceRepresentation) +
60+
compartmentIdVariableStr + CpeDeviceShapeResourceConfig,
61+
62+
Check: resource.ComposeAggregateTestCheckFunc(
63+
resource.TestCheckResourceAttrSet(singularDatasourceName, "cpe_device_shape_id"),
64+
65+
resource.TestCheckResourceAttr(singularDatasourceName, "cpe_device_info.#", "1"),
66+
resource.TestCheckResourceAttrSet(singularDatasourceName, "cpe_device_shape_id"),
67+
resource.TestCheckResourceAttrSet(singularDatasourceName, "template"),
68+
),
69+
},
70+
},
71+
})
72+
}

0 commit comments

Comments
 (0)