Skip to content

Commit 172ac33

Browse files
Terraform Team AutomationMaxrovr
authored andcommitted
Added - Support for Capacity Availability API
1 parent dca5212 commit 172ac33

File tree

11 files changed

+645
-0
lines changed

11 files changed

+645
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
provider "oci" {
2+
tenancy_ocid = var.compartment_ocid
3+
region = var.region
4+
user_ocid = var.user_ocid
5+
fingerprint = var.fingerprint
6+
private_key_path = var.private_key_path
7+
retry_duration_seconds = "1800"
8+
}
9+
10+
data "oci_identity_availability_domain" "ad" {
11+
compartment_id = var.tenancy_ocid
12+
ad_number = 1
13+
}
14+
15+
resource "oci_core_compute_capacity_report" "test_compute_capacity_report_flex_shape" {
16+
#Required
17+
availability_domain = data.oci_identity_availability_domain.ad.name
18+
compartment_id = var.compartment_ocid
19+
shape_availabilities {
20+
#Required
21+
instance_shape = var.compute_capacity_report_shape_availabilities_instance_shape_flex
22+
23+
#Optional
24+
fault_domain = var.compute_capacity_report_shape_availabilities_fault_domain
25+
instance_shape_config {
26+
27+
#Optional
28+
memory_in_gbs = var.compute_capacity_report_shape_availabilities_instance_shape_config_memory_in_gbs
29+
nvmes = var.compute_capacity_report_shape_availabilities_instance_shape_config_nvmes
30+
ocpus = var.compute_capacity_report_shape_availabilities_instance_shape_config_ocpus
31+
}
32+
}
33+
}
34+
35+
resource "oci_core_compute_capacity_report" "test_compute_capacity_report_fix_shape" {
36+
#Required
37+
availability_domain = data.oci_identity_availability_domain.ad.name
38+
compartment_id = var.compartment_ocid
39+
shape_availabilities {
40+
#Required
41+
instance_shape = var.compute_capacity_report_shape_availabilities_instance_shape_fix
42+
}
43+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
variable "region" {
2+
description = "region in which to call API."
3+
}
4+
5+
variable "compartment_ocid" {
6+
description = "compartment_id in which to call API."
7+
}
8+
9+
variable "tenancy_ocid" {
10+
description = "tenancy OCID in which to launch instances."
11+
}
12+
13+
variable "user_ocid" {
14+
description = "user OCID for the user account with which to connect to the API."
15+
}
16+
17+
variable "private_key_path" {
18+
description = "full file path of the private key to use for API access with the user account. Does not support environment variables or ~ to abbreviate a user's home directory."
19+
}
20+
21+
variable "fingerprint" {
22+
description = "PEM fingerprint for private key."
23+
}
24+
25+
variable "compute_capacity_report_availability_domain" {
26+
description = "AD in which to call API."
27+
default = "UgLr:PHX-AD-1"
28+
}
29+
30+
variable "compute_capacity_report_shape_availabilities_fault_domain" {
31+
description = "FD in which to call API."
32+
}
33+
34+
variable "compute_capacity_report_shape_availabilities_instance_shape_flex" {
35+
default = "VM.Standard.E4.Flex"
36+
}
37+
variable "compute_capacity_report_shape_availabilities_instance_shape_fix" {
38+
default = "VM.Standard1.8"
39+
}
40+
41+
variable "compute_capacity_report_shape_availabilities_instance_shape_config_memory_in_gbs" {
42+
default = 16
43+
}
44+
45+
variable "compute_capacity_report_shape_availabilities_instance_shape_config_nvmes" {
46+
default = 2
47+
}
48+
49+
variable "compute_capacity_report_shape_availabilities_instance_shape_config_ocpus" {
50+
default = 1
51+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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+
"strconv"
9+
"testing"
10+
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
12+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
13+
14+
"github.com/oracle/terraform-provider-oci/httpreplay"
15+
"github.com/oracle/terraform-provider-oci/internal/acctest"
16+
17+
"github.com/oracle/terraform-provider-oci/internal/resourcediscovery"
18+
19+
"github.com/oracle/terraform-provider-oci/internal/utils"
20+
)
21+
22+
var (
23+
CoreComputeCapacityReportRepresentation = map[string]interface{}{
24+
"availability_domain": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}`},
25+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
26+
"shape_availabilities": acctest.RepresentationGroup{RepType: acctest.Required,
27+
Group: CoreComputeCapacityReportShapeAvailabilitiesRepresentation},
28+
}
29+
CoreComputeCapacityReportShapeAvailabilitiesRepresentation = map[string]interface{}{
30+
"instance_shape": acctest.Representation{RepType: acctest.Required, Create: `VM.Standard1.8`},
31+
"fault_domain": acctest.Representation{RepType: acctest.Optional, Create: `FAULT-DOMAIN-1`},
32+
}
33+
34+
CoreComputeCapacityReportRepresentationWithShapeConfig = map[string]interface{}{
35+
"availability_domain": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}`},
36+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
37+
"shape_availabilities": acctest.RepresentationGroup{RepType: acctest.Required,
38+
Group: CoreComputeCapacityReportShapeAvailabilitiesRepresentationWithShapeConfig},
39+
}
40+
CoreComputeCapacityReportShapeAvailabilitiesRepresentationWithShapeConfig = map[string]interface{}{
41+
"instance_shape": acctest.Representation{RepType: acctest.Required, Create: `VM.Standard.E4.Flex`},
42+
"fault_domain": acctest.Representation{RepType: acctest.Optional, Create: `FAULT-DOMAIN-1`},
43+
"instance_shape_config": acctest.RepresentationGroup{RepType: acctest.Required,
44+
Group: CoreComputeCapacityReportShapeAvailabilitiesInstanceShapeConfigRepresentationWithShapeConfig},
45+
}
46+
CoreComputeCapacityReportShapeAvailabilitiesInstanceShapeConfigRepresentationWithShapeConfig = map[string]interface{}{
47+
"memory_in_gbs": acctest.Representation{RepType: acctest.Required, Create: `16`},
48+
"nvmes": acctest.Representation{RepType: acctest.Optional, Create: `10`},
49+
"ocpus": acctest.Representation{RepType: acctest.Required, Create: `1`},
50+
}
51+
52+
CoreComputeCapacityReportResourceDependencies = AvailabilityDomainConfig
53+
)
54+
55+
// issue-routing-tag: core/computeSharedOwnershipVmAndBm
56+
func TestCoreComputeCapacityReportResource_basic(t *testing.T) {
57+
httpreplay.SetScenario("TestCoreComputeCapacityReportResource_basic")
58+
defer httpreplay.SaveScenario()
59+
60+
config := acctest.ProviderTestConfig()
61+
62+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
63+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
64+
65+
resourceName := "oci_core_compute_capacity_report.test_compute_capacity_report"
66+
67+
var resId string
68+
// Save TF content to Create resource with only required properties. This has to be exactly the same as the config part in the create step in the test.
69+
acctest.SaveConfigContent(config+compartmentIdVariableStr+CoreComputeCapacityReportResourceDependencies+
70+
acctest.GenerateResourceFromRepresentationMap("oci_core_compute_capacity_report", "test_compute_capacity_report", acctest.Required, acctest.Create, CoreComputeCapacityReportRepresentation), "core", "computeCapacityReport", t)
71+
72+
acctest.ResourceTest(t, nil, []resource.TestStep{
73+
// verify Create
74+
{
75+
Config: config + compartmentIdVariableStr + CoreComputeCapacityReportResourceDependencies +
76+
acctest.GenerateResourceFromRepresentationMap("oci_core_compute_capacity_report", "test_compute_capacity_report", acctest.Required, acctest.Create, CoreComputeCapacityReportRepresentation),
77+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
78+
resource.TestCheckResourceAttrSet(resourceName, "availability_domain"),
79+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
80+
resource.TestCheckResourceAttr(resourceName, "shape_availabilities.0.instance_shape", "VM.Standard1.8"),
81+
82+
func(s *terraform.State) (err error) {
83+
resId, err = acctest.FromInstanceState(s, resourceName, "id")
84+
if isEnableExportCompartment, _ := strconv.ParseBool(utils.GetEnvSettingWithDefault("enable_export_compartment", "true")); isEnableExportCompartment {
85+
if errExport := resourcediscovery.TestExportCompartmentWithResourceName(&resId, &compartmentId, resourceName); errExport != nil {
86+
return errExport
87+
}
88+
}
89+
return err
90+
},
91+
),
92+
},
93+
})
94+
}
95+
96+
func TestCoreComputeCapacityReportResource_withShapeConfig(t *testing.T) {
97+
httpreplay.SetScenario("TestCoreComputeCapacityReportResource_withShapeConfig")
98+
defer httpreplay.SaveScenario()
99+
100+
config := acctest.ProviderTestConfig()
101+
102+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
103+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
104+
105+
resourceName := "oci_core_compute_capacity_report.test_compute_capacity_report"
106+
107+
var resId string
108+
// Save TF content to Create resource with only required properties. This has to be exactly the same as the config part in the create step in the test.
109+
acctest.SaveConfigContent(config+compartmentIdVariableStr+CoreComputeCapacityReportResourceDependencies+
110+
acctest.GenerateResourceFromRepresentationMap("oci_core_compute_capacity_report", "test_compute_capacity_report", acctest.Required, acctest.Create, CoreComputeCapacityReportRepresentationWithShapeConfig), "core", "computeCapacityReport", t)
111+
112+
acctest.ResourceTest(t, nil, []resource.TestStep{
113+
// verify Create
114+
{
115+
Config: config + compartmentIdVariableStr + CoreComputeCapacityReportResourceDependencies +
116+
acctest.GenerateResourceFromRepresentationMap("oci_core_compute_capacity_report", "test_compute_capacity_report", acctest.Required, acctest.Create, CoreComputeCapacityReportRepresentationWithShapeConfig),
117+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
118+
resource.TestCheckResourceAttrSet(resourceName, "availability_domain"),
119+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
120+
resource.TestCheckResourceAttr(resourceName, "shape_availabilities.0.instance_shape", "VM.Standard.E4.Flex"),
121+
122+
func(s *terraform.State) (err error) {
123+
resId, err = acctest.FromInstanceState(s, resourceName, "id")
124+
if isEnableExportCompartment, _ := strconv.ParseBool(utils.GetEnvSettingWithDefault("enable_export_compartment", "true")); isEnableExportCompartment {
125+
if errExport := resourcediscovery.TestExportCompartmentWithResourceName(&resId, &compartmentId, resourceName); errExport != nil {
126+
return errExport
127+
}
128+
}
129+
return err
130+
},
131+
),
132+
},
133+
})
134+
}

0 commit comments

Comments
 (0)