Skip to content

Commit b7c7912

Browse files
Bhagyashree Shettyvarmax2511
authored andcommitted
Added - Support for Service Manager Proxy service
1 parent 3f13f31 commit b7c7912

6 files changed

+697
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package oci
5+
6+
import (
7+
oci_service_manager_proxy "github.com/oracle/oci-go-sdk/v51/servicemanagerproxy"
8+
9+
oci_common "github.com/oracle/oci-go-sdk/v51/common"
10+
)
11+
12+
func init() {
13+
RegisterOracleClient("oci_service_manager_proxy.ServiceManagerProxyClient", &OracleClient{InitClientFn: initServicemanagerproxyServiceManagerProxyClient})
14+
}
15+
16+
func initServicemanagerproxyServiceManagerProxyClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient, serviceClientOverrides ServiceClientOverrides) (interface{}, error) {
17+
client, err := oci_service_manager_proxy.NewServiceManagerProxyClientWithConfigurationProvider(configProvider)
18+
if err != nil {
19+
return nil, err
20+
}
21+
err = configureClient(&client.BaseClient)
22+
if err != nil {
23+
return nil, err
24+
}
25+
26+
if serviceClientOverrides.hostUrlOverride != "" {
27+
client.Host = serviceClientOverrides.hostUrlOverride
28+
}
29+
return &client, nil
30+
}
31+
32+
func (m *OracleClients) serviceManagerProxyClient() *oci_service_manager_proxy.ServiceManagerProxyClient {
33+
return m.GetClient("oci_service_manager_proxy.ServiceManagerProxyClient").(*oci_service_manager_proxy.ServiceManagerProxyClient)
34+
}
Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package oci
5+
6+
import (
7+
"context"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
10+
oci_service_manager_proxy "github.com/oracle/oci-go-sdk/v51/servicemanagerproxy"
11+
)
12+
13+
func init() {
14+
RegisterDatasource("oci_service_manager_proxy_service_environment", ServiceManagerProxyServiceEnvironmentDataSource())
15+
}
16+
17+
func ServiceManagerProxyServiceEnvironmentDataSource() *schema.Resource {
18+
return &schema.Resource{
19+
Read: readSingularServiceManagerProxyServiceEnvironment,
20+
Schema: map[string]*schema.Schema{
21+
"compartment_id": {
22+
Type: schema.TypeString,
23+
Required: true,
24+
},
25+
"service_environment_id": {
26+
Type: schema.TypeString,
27+
Required: true,
28+
},
29+
// Computed
30+
"console_url": {
31+
Type: schema.TypeString,
32+
Computed: true,
33+
},
34+
"service_definition": {
35+
Type: schema.TypeList,
36+
Computed: true,
37+
Elem: &schema.Resource{
38+
Schema: map[string]*schema.Schema{
39+
// Required
40+
41+
// Optional
42+
43+
// Computed
44+
"display_name": {
45+
Type: schema.TypeString,
46+
Computed: true,
47+
},
48+
"short_display_name": {
49+
Type: schema.TypeString,
50+
Computed: true,
51+
},
52+
"type": {
53+
Type: schema.TypeString,
54+
Computed: true,
55+
},
56+
},
57+
},
58+
},
59+
"service_environment_endpoints": {
60+
Type: schema.TypeList,
61+
Computed: true,
62+
Elem: &schema.Resource{
63+
Schema: map[string]*schema.Schema{
64+
// Required
65+
66+
// Optional
67+
68+
// Computed
69+
"environment_type": {
70+
Type: schema.TypeString,
71+
Computed: true,
72+
},
73+
"url": {
74+
Type: schema.TypeString,
75+
Computed: true,
76+
},
77+
},
78+
},
79+
},
80+
"status": {
81+
Type: schema.TypeString,
82+
Computed: true,
83+
},
84+
"subscription_id": {
85+
Type: schema.TypeString,
86+
Computed: true,
87+
},
88+
},
89+
}
90+
}
91+
92+
func readSingularServiceManagerProxyServiceEnvironment(d *schema.ResourceData, m interface{}) error {
93+
sync := &ServiceManagerProxyServiceEnvironmentDataSourceCrud{}
94+
sync.D = d
95+
sync.Client = m.(*OracleClients).serviceManagerProxyClient()
96+
97+
return ReadResource(sync)
98+
}
99+
100+
type ServiceManagerProxyServiceEnvironmentDataSourceCrud struct {
101+
D *schema.ResourceData
102+
Client *oci_service_manager_proxy.ServiceManagerProxyClient
103+
Res *oci_service_manager_proxy.GetServiceEnvironmentResponse
104+
}
105+
106+
func (s *ServiceManagerProxyServiceEnvironmentDataSourceCrud) VoidState() {
107+
s.D.SetId("")
108+
}
109+
110+
func (s *ServiceManagerProxyServiceEnvironmentDataSourceCrud) Get() error {
111+
request := oci_service_manager_proxy.GetServiceEnvironmentRequest{}
112+
113+
if compartmentId, ok := s.D.GetOkExists("compartment_id"); ok {
114+
tmp := compartmentId.(string)
115+
request.CompartmentId = &tmp
116+
}
117+
118+
if serviceEnvironmentId, ok := s.D.GetOkExists("service_environment_id"); ok {
119+
tmp := serviceEnvironmentId.(string)
120+
request.ServiceEnvironmentId = &tmp
121+
}
122+
123+
request.RequestMetadata.RetryPolicy = GetRetryPolicy(false, "service_manager_proxy")
124+
125+
response, err := s.Client.GetServiceEnvironment(context.Background(), request)
126+
if err != nil {
127+
return err
128+
}
129+
130+
s.Res = &response
131+
return nil
132+
}
133+
134+
func (s *ServiceManagerProxyServiceEnvironmentDataSourceCrud) SetData() error {
135+
if s.Res == nil {
136+
return nil
137+
}
138+
139+
s.D.SetId(*s.Res.Id)
140+
141+
s.D.Set("compartment_id", *s.Res.CompartmentId)
142+
143+
if s.Res.ConsoleUrl != nil {
144+
s.D.Set("console_url", *s.Res.ConsoleUrl)
145+
}
146+
147+
if s.Res.ServiceDefinition != nil {
148+
s.D.Set("service_definition", []interface{}{ServiceDefinitionToMap(s.Res.ServiceDefinition)})
149+
} else {
150+
s.D.Set("service_definition", nil)
151+
}
152+
153+
serviceEnvironmentEndpoints := []interface{}{}
154+
for _, item := range s.Res.ServiceEnvironmentEndpoints {
155+
serviceEnvironmentEndpoints = append(serviceEnvironmentEndpoints, ServiceEnvironmentEndPointOverviewToMap(item))
156+
}
157+
s.D.Set("service_environment_endpoints", serviceEnvironmentEndpoints)
158+
159+
s.D.Set("status", s.Res.Status)
160+
161+
if s.Res.SubscriptionId != nil {
162+
s.D.Set("subscription_id", *s.Res.SubscriptionId)
163+
}
164+
165+
return nil
166+
}
167+
168+
func ServiceDefinitionToMap(obj *oci_service_manager_proxy.ServiceDefinition) map[string]interface{} {
169+
result := map[string]interface{}{}
170+
171+
if obj.DisplayName != nil {
172+
result["display_name"] = string(*obj.DisplayName)
173+
}
174+
175+
if obj.ShortDisplayName != nil {
176+
result["short_display_name"] = string(*obj.ShortDisplayName)
177+
}
178+
179+
if obj.Type != nil {
180+
result["type"] = string(*obj.Type)
181+
}
182+
183+
return result
184+
}
185+
186+
func ServiceEnvironmentEndPointOverviewToMap(obj oci_service_manager_proxy.ServiceEnvironmentEndPointOverview) map[string]interface{} {
187+
result := map[string]interface{}{}
188+
189+
result["environment_type"] = string(obj.EnvironmentType)
190+
191+
if obj.Url != nil {
192+
result["url"] = string(*obj.Url)
193+
}
194+
195+
return result
196+
}
197+
198+
func ServiceEnvironmentSummaryToMap(obj oci_service_manager_proxy.ServiceEnvironmentSummary) map[string]interface{} {
199+
result := map[string]interface{}{}
200+
201+
if obj.CompartmentId != nil {
202+
result["compartment_id"] = string(*obj.CompartmentId)
203+
}
204+
205+
if obj.ConsoleUrl != nil {
206+
result["console_url"] = string(*obj.ConsoleUrl)
207+
}
208+
209+
if obj.DefinedTags != nil {
210+
result["defined_tags"] = definedTagsToMap(obj.DefinedTags)
211+
}
212+
213+
result["freeform_tags"] = obj.FreeformTags
214+
215+
if obj.Id != nil {
216+
result["id"] = string(*obj.Id)
217+
}
218+
219+
if obj.ServiceDefinition != nil {
220+
result["service_definition"] = []interface{}{ServiceDefinitionToMap(obj.ServiceDefinition)}
221+
}
222+
223+
serviceEnvironmentEndpoints := []interface{}{}
224+
for _, item := range obj.ServiceEnvironmentEndpoints {
225+
serviceEnvironmentEndpoints = append(serviceEnvironmentEndpoints, ServiceEnvironmentEndPointOverviewToMap(item))
226+
}
227+
result["service_environment_endpoints"] = serviceEnvironmentEndpoints
228+
229+
result["status"] = string(obj.Status)
230+
231+
if obj.SubscriptionId != nil {
232+
result["subscription_id"] = string(*obj.SubscriptionId)
233+
}
234+
235+
return result
236+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package oci
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
11+
12+
"github.com/terraform-providers/terraform-provider-oci/httpreplay"
13+
)
14+
15+
var (
16+
serviceEnvironmentSingularDataSourceRepresentation = map[string]interface{}{
17+
"compartment_id": Representation{RepType: Required, Create: `${var.compartment_id}`},
18+
"service_environment_id": Representation{RepType: Required, Create: `${var.service_environment_id}`},
19+
}
20+
21+
ServiceEnvironmentResourceConfig = GenerateDataSourceFromRepresentationMap("oci_service_manager_proxy_service_environment", "test_service_environment", Required, Create, serviceEnvironmentSingularDataSourceRepresentation)
22+
23+
serviceEnvironmentDataSourceRepresentation = map[string]interface{}{
24+
"compartment_id": Representation{RepType: Required, Create: `${var.compartment_id}`},
25+
}
26+
27+
ServiceEnvironmentsResourceConfig = GenerateDataSourceFromRepresentationMap("oci_service_manager_proxy_service_environments", "test_service_environments", Required, Create, serviceEnvironmentDataSourceRepresentation)
28+
)
29+
30+
// issue-routing-tag: service_manager_proxy/default
31+
func TestServiceManagerProxyServiceEnvironmentResource_basic(t *testing.T) {
32+
httpreplay.SetScenario("TestServiceManagerProxyServiceEnvironmentResource_basic")
33+
defer httpreplay.SaveScenario()
34+
35+
config := testProviderConfig()
36+
37+
compartmentId := getEnvSettingWithBlankDefault("compartment_ocid")
38+
serviceEnvironmentId := getEnvSettingWithBlankDefault("service_environment_id")
39+
40+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
41+
serviceEnvironmentIdVariableStr := fmt.Sprintf("variable \"service_environment_id\" { default = \"%s\" }\n", serviceEnvironmentId)
42+
43+
datasourceName := "data.oci_service_manager_proxy_service_environments.test_service_environments"
44+
singularDatasourceName := "data.oci_service_manager_proxy_service_environment.test_service_environment"
45+
46+
SaveConfigContent("", "", "", t)
47+
48+
ResourceTest(t, nil, []resource.TestStep{
49+
// verify datasource
50+
{
51+
Config: config +
52+
GenerateDataSourceFromRepresentationMap("oci_service_manager_proxy_service_environments", "test_service_environments", Required, Create, serviceEnvironmentDataSourceRepresentation) +
53+
compartmentIdVariableStr,
54+
55+
Check: ComposeAggregateTestCheckFuncWrapper(
56+
resource.TestCheckResourceAttrSet(datasourceName, "compartment_id"),
57+
resource.TestCheckResourceAttrSet(datasourceName, "id"),
58+
resource.TestCheckResourceAttrSet(datasourceName, "service_environment_collection.0.items.0.service_definition.0.display_name"),
59+
resource.TestCheckResourceAttrSet(datasourceName, "service_environment_collection.0.items.0.service_definition.0.type"),
60+
resource.TestCheckResourceAttr(datasourceName, "service_environment_collection.#", "1"),
61+
),
62+
},
63+
// verify singular datasource
64+
{
65+
Config: config +
66+
GenerateDataSourceFromRepresentationMap("oci_service_manager_proxy_service_environment", "test_service_environment", Required, Create, serviceEnvironmentSingularDataSourceRepresentation) +
67+
compartmentIdVariableStr + serviceEnvironmentIdVariableStr,
68+
69+
Check: ComposeAggregateTestCheckFuncWrapper(
70+
resource.TestCheckResourceAttrSet(singularDatasourceName, "compartment_id"),
71+
resource.TestCheckResourceAttrSet(singularDatasourceName, "service_environment_id"),
72+
73+
resource.TestCheckResourceAttrSet(singularDatasourceName, "console_url"),
74+
resource.TestCheckResourceAttrSet(singularDatasourceName, "id"),
75+
resource.TestCheckResourceAttr(singularDatasourceName, "service_definition.#", "1"),
76+
resource.TestCheckResourceAttrSet(singularDatasourceName, "status"),
77+
resource.TestCheckResourceAttrSet(singularDatasourceName, "subscription_id"),
78+
),
79+
},
80+
})
81+
}

0 commit comments

Comments
 (0)