|
| 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