Skip to content

Commit 90835bf

Browse files
Deepthi Ramakrishnajotruon
authored andcommitted
Added - Support for Usage proxy: Adding APIs for MQS public API deprecation
1 parent 60de163 commit 90835bf

13 files changed

+1312
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
// These variables would commonly be defined as environment variables or sourced in a .env file
5+
6+
variable "region" {
7+
}
8+
9+
variable "fingerprint" {
10+
}
11+
12+
variable "tenancy_ocid" {
13+
}
14+
15+
variable "compartment_ocid" {
16+
}
17+
18+
variable "service_name" {
19+
}
20+
21+
variable "user_ocid" {
22+
}
23+
24+
variable "private_key_path" {
25+
}
26+
27+
provider "oci" {
28+
region = var.region
29+
tenancy_ocid = var.tenancy_ocid
30+
user_ocid = var.user_ocid
31+
fingerprint = var.fingerprint
32+
private_key_path = var.private_key_path
33+
}
34+
35+
data "oci_usage_proxy_resource_quotas" "test_resource_quotas" {
36+
#Required
37+
compartment_id = var.compartment_ocid
38+
service_name = var.service_name
39+
}
40+
41+
data "oci_usage_proxy_resources" "test_resources" {
42+
#Required
43+
compartment_id = var.compartment_ocid
44+
service_name = var.service_name
45+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
// These variables would commonly be defined as environment variables or sourced in a .env file
5+
6+
variable "region" {
7+
}
8+
9+
variable "fingerprint" {
10+
}
11+
12+
variable "tenancy_ocid" {
13+
}
14+
15+
variable "compartment_ocid" {
16+
}
17+
18+
variable "subscription_id" {
19+
}
20+
21+
variable "user_ocid" {
22+
}
23+
24+
variable "private_key_path" {
25+
}
26+
27+
provider "oci" {
28+
region = var.region
29+
tenancy_ocid = var.tenancy_ocid
30+
user_ocid = var.user_ocid
31+
fingerprint = var.fingerprint
32+
private_key_path = var.private_key_path
33+
}
34+
35+
data "oci_usage_proxy_usagelimits" "test_usagelimits" {
36+
#Required
37+
compartment_id = var.compartment_ocid
38+
subscription_id = var.subscription_id
39+
}

internal/client/usage_proxy_clients.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,29 @@ import (
1010
)
1111

1212
func init() {
13+
RegisterOracleClient("oci_usage_proxy.ResourcesClient", &OracleClient{InitClientFn: initUsageResourcesClient})
1314
RegisterOracleClient("oci_usage_proxy.RewardsClient", &OracleClient{InitClientFn: initUsageRewardsClient})
15+
RegisterOracleClient("oci_usage_proxy.UsagelimitsClient", &OracleClient{InitClientFn: initUsageUsagelimitsClient})
16+
}
17+
18+
func initUsageResourcesClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient, serviceClientOverrides ServiceClientOverrides) (interface{}, error) {
19+
client, err := oci_usage_proxy.NewResourcesClientWithConfigurationProvider(configProvider)
20+
if err != nil {
21+
return nil, err
22+
}
23+
err = configureClient(&client.BaseClient)
24+
if err != nil {
25+
return nil, err
26+
}
27+
28+
if serviceClientOverrides.HostUrlOverride != "" {
29+
client.Host = serviceClientOverrides.HostUrlOverride
30+
}
31+
return &client, nil
32+
}
33+
34+
func (m *OracleClients) ResourcesClient() *oci_usage_proxy.ResourcesClient {
35+
return m.GetClient("oci_usage_proxy.ResourcesClient").(*oci_usage_proxy.ResourcesClient)
1436
}
1537

1638
func initUsageRewardsClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient, serviceClientOverrides ServiceClientOverrides) (interface{}, error) {
@@ -32,3 +54,23 @@ func initUsageRewardsClient(configProvider oci_common.ConfigurationProvider, con
3254
func (m *OracleClients) RewardsClient() *oci_usage_proxy.RewardsClient {
3355
return m.GetClient("oci_usage_proxy.RewardsClient").(*oci_usage_proxy.RewardsClient)
3456
}
57+
58+
func initUsageUsagelimitsClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient, serviceClientOverrides ServiceClientOverrides) (interface{}, error) {
59+
client, err := oci_usage_proxy.NewUsagelimitsClientWithConfigurationProvider(configProvider)
60+
if err != nil {
61+
return nil, err
62+
}
63+
err = configureClient(&client.BaseClient)
64+
if err != nil {
65+
return nil, err
66+
}
67+
68+
if serviceClientOverrides.HostUrlOverride != "" {
69+
client.Host = serviceClientOverrides.HostUrlOverride
70+
}
71+
return &client, nil
72+
}
73+
74+
func (m *OracleClients) UsagelimitsClient() *oci_usage_proxy.UsagelimitsClient {
75+
return m.GetClient("oci_usage_proxy.UsagelimitsClient").(*oci_usage_proxy.UsagelimitsClient)
76+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 integrationtest
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11+
12+
"github.com/oracle/terraform-provider-oci/httpreplay"
13+
"github.com/oracle/terraform-provider-oci/internal/acctest"
14+
15+
"github.com/oracle/terraform-provider-oci/internal/utils"
16+
)
17+
18+
var (
19+
UsageProxyResourceQuotaDataSourceRepresentation = map[string]interface{}{
20+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
21+
"service_name": acctest.Representation{RepType: acctest.Required, Create: `${var.service_name}`},
22+
"service_entitlement": acctest.Representation{RepType: acctest.Optional, Create: `serviceEntitlement`},
23+
}
24+
25+
UsageProxyResourceQuotaResourceConfig = ""
26+
)
27+
28+
// issue-routing-tag: usage_proxy/default
29+
func TestUsageProxyResourceQuotaResource_basic(t *testing.T) {
30+
httpreplay.SetScenario("TestUsageProxyResourceQuotaResource_basic")
31+
defer httpreplay.SaveScenario()
32+
33+
config := acctest.ProviderTestConfig()
34+
35+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
36+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
37+
38+
serviceName := utils.GetEnvSettingWithBlankDefault("service_name")
39+
serviceNameVariableStr := fmt.Sprintf("variable \"service_name\" { default = \"%s\" }\n", serviceName)
40+
41+
datasourceName := "data.oci_usage_proxy_resource_quotas.test_resource_quotas"
42+
43+
acctest.SaveConfigContent("", "", "", t)
44+
45+
acctest.ResourceTest(t, nil, []resource.TestStep{
46+
// verify datasource
47+
{
48+
Config: config +
49+
acctest.GenerateDataSourceFromRepresentationMap("oci_usage_proxy_resource_quotas", "test_resource_quotas", acctest.Required, acctest.Create, UsageProxyResourceQuotaDataSourceRepresentation) +
50+
compartmentIdVariableStr + serviceNameVariableStr + UsageProxyResourceQuotaResourceConfig,
51+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
52+
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
53+
resource.TestCheckResourceAttrSet(datasourceName, "service_name"),
54+
55+
resource.TestCheckResourceAttrSet(datasourceName, "resource_quotum_collection.#"),
56+
resource.TestCheckResourceAttrSet(datasourceName, "resource_quotum_collection.0.is_allowed"),
57+
resource.TestCheckResourceAttrSet(datasourceName, "resource_quotum_collection.0.items.#"),
58+
),
59+
},
60+
})
61+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 integrationtest
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11+
12+
"github.com/oracle/terraform-provider-oci/httpreplay"
13+
"github.com/oracle/terraform-provider-oci/internal/acctest"
14+
15+
"github.com/oracle/terraform-provider-oci/internal/utils"
16+
)
17+
18+
var (
19+
UsageProxyResourceDataSourceRepresentation = map[string]interface{}{
20+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
21+
"service_name": acctest.Representation{RepType: acctest.Required, Create: `${var.service_name}`},
22+
"entitlement_id": acctest.Representation{RepType: acctest.Optional, Create: `${var.entitlement_id}`},
23+
}
24+
25+
UsageProxyResourceResourceConfig = ""
26+
)
27+
28+
// issue-routing-tag: usage_proxy/default
29+
func TestUsageProxyResourceResource_basic(t *testing.T) {
30+
httpreplay.SetScenario("TestUsageProxyResourceResource_basic")
31+
defer httpreplay.SaveScenario()
32+
33+
config := acctest.ProviderTestConfig()
34+
35+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
36+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
37+
38+
serviceName := utils.GetEnvSettingWithBlankDefault("service_name")
39+
serviceNameVariableStr := fmt.Sprintf("variable \"service_name\" { default = \"%s\" }\n", serviceName)
40+
41+
entitlementId := utils.GetEnvSettingWithBlankDefault("entitlement_id")
42+
entitlementIdVariableStr := fmt.Sprintf("variable \"entitlement_id\" { default = \"%s\" }\n", entitlementId)
43+
44+
datasourceName := "data.oci_usage_proxy_resources.test_resources"
45+
46+
acctest.SaveConfigContent("", "", "", t)
47+
48+
acctest.ResourceTest(t, nil, []resource.TestStep{
49+
// verify datasource
50+
{
51+
Config: config +
52+
acctest.GenerateDataSourceFromRepresentationMap("oci_usage_proxy_resources", "test_resources", acctest.Required, acctest.Create, UsageProxyResourceDataSourceRepresentation) +
53+
compartmentIdVariableStr + serviceNameVariableStr + entitlementIdVariableStr + UsageProxyResourceResourceConfig,
54+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
55+
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
56+
resource.TestCheckResourceAttrSet(datasourceName, "service_name"),
57+
58+
resource.TestCheckResourceAttrSet(datasourceName, "resources_collection.#"),
59+
resource.TestCheckResourceAttrSet(datasourceName, "resources_collection.0.items.#"),
60+
),
61+
},
62+
})
63+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 integrationtest
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11+
12+
"github.com/oracle/terraform-provider-oci/httpreplay"
13+
"github.com/oracle/terraform-provider-oci/internal/acctest"
14+
15+
"github.com/oracle/terraform-provider-oci/internal/utils"
16+
)
17+
18+
var (
19+
UsageProxyUsagelimitDataSourceRepresentation = map[string]interface{}{
20+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
21+
"subscription_id": acctest.Representation{RepType: acctest.Required, Create: `${var.subscription_id}`},
22+
"limit_type": acctest.Representation{RepType: acctest.Optional, Create: `limitType`},
23+
"resource_type": acctest.Representation{RepType: acctest.Optional, Create: `resourceType`},
24+
"service_type": acctest.Representation{RepType: acctest.Optional, Create: `serviceType`},
25+
}
26+
27+
UsageProxyUsagelimitResourceConfig = ""
28+
)
29+
30+
// issue-routing-tag: usage_proxy/default
31+
func TestUsageProxyUsagelimitResource_basic(t *testing.T) {
32+
httpreplay.SetScenario("TestUsageProxyUsagelimitResource_basic")
33+
defer httpreplay.SaveScenario()
34+
35+
config := acctest.ProviderTestConfig()
36+
37+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
38+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
39+
40+
subscriptionId := utils.GetEnvSettingWithBlankDefault("subscription_id")
41+
subscriptionIdVariableStr := fmt.Sprintf("variable \"subscription_id\" { default = \"%s\" }\n", subscriptionId)
42+
43+
datasourceName := "data.oci_usage_proxy_usagelimits.test_usagelimits"
44+
45+
acctest.SaveConfigContent("", "", "", t)
46+
47+
acctest.ResourceTest(t, nil, []resource.TestStep{
48+
// verify datasource
49+
{
50+
Config: config +
51+
acctest.GenerateDataSourceFromRepresentationMap("oci_usage_proxy_usagelimits", "test_usagelimits", acctest.Required, acctest.Create, UsageProxyUsagelimitDataSourceRepresentation) +
52+
compartmentIdVariableStr + subscriptionIdVariableStr + UsageProxyUsagelimitResourceConfig,
53+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
54+
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
55+
56+
resource.TestCheckResourceAttrSet(datasourceName, "usage_limit_collection.#"),
57+
resource.TestCheckResourceAttr(datasourceName, "usage_limit_collection.0.items.#", "1"),
58+
resource.TestCheckResourceAttrSet(datasourceName, "usage_limit_collection.0.items.0.entitlement_id"),
59+
resource.TestCheckResourceAttrSet(datasourceName, "usage_limit_collection.0.items.0.limit_type"),
60+
),
61+
},
62+
})
63+
}

internal/service/usage_proxy/register_datasource.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package usage_proxy
66
import "github.com/oracle/terraform-provider-oci/internal/tfresource"
77

88
func RegisterDatasource() {
9+
tfresource.RegisterDatasource("oci_usage_proxy_resource_quotas", UsageProxyResourceQuotasDataSource())
10+
tfresource.RegisterDatasource("oci_usage_proxy_resources", UsageProxyResourcesDataSource())
911
tfresource.RegisterDatasource("oci_usage_proxy_subscription_product", UsageProxySubscriptionProductDataSource())
1012
tfresource.RegisterDatasource("oci_usage_proxy_subscription_products", UsageProxySubscriptionProductsDataSource())
1113
tfresource.RegisterDatasource("oci_usage_proxy_subscription_redeemable_user", UsageProxySubscriptionRedeemableUserDataSource())
@@ -14,4 +16,5 @@ func RegisterDatasource() {
1416
tfresource.RegisterDatasource("oci_usage_proxy_subscription_redemptions", UsageProxySubscriptionRedemptionsDataSource())
1517
tfresource.RegisterDatasource("oci_usage_proxy_subscription_reward", UsageProxySubscriptionRewardDataSource())
1618
tfresource.RegisterDatasource("oci_usage_proxy_subscription_rewards", UsageProxySubscriptionRewardsDataSource())
19+
tfresource.RegisterDatasource("oci_usage_proxy_usagelimits", UsageProxyUsagelimitsDataSource())
1720
}

0 commit comments

Comments
 (0)