Skip to content

Commit 565f0b4

Browse files
AravindOraclesankhsin
authored andcommitted
updating instance_reservation_configs field in oci_core_compute_capacity_reservation to typeSet
1 parent b2207a2 commit 565f0b4

File tree

4 files changed

+121
-15
lines changed

4 files changed

+121
-15
lines changed

internal/integrationtest/core_compute_capacity_reservation_test.go

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,37 @@ var (
6464
"instance_shape_config": acctest.RepresentationGroup{RepType: acctest.Optional, Group: CoreComputeCapacityReservationInstanceReservationConfigsInstanceShapeConfigRepresentation},
6565
}
6666

67+
CoreComputeCapacityReservationInstanceReservationConfigsRepresentation2 = map[string]interface{}{
68+
"instance_shape": acctest.Representation{RepType: acctest.Required, Create: `VM.Standard.E5.Flex`},
69+
"fault_domain": acctest.Representation{RepType: acctest.Optional, Create: `FAULT-DOMAIN-1`},
70+
"cluster_placement_group_id": acctest.Representation{RepType: acctest.Optional, Create: `${var.cluster_placement_group_id2}`},
71+
"reserved_count": acctest.Representation{RepType: acctest.Required, Create: `1`, Update: `2`},
72+
"instance_shape_config": acctest.RepresentationGroup{RepType: acctest.Required, Group: CoreComputeCapacityReservationInstanceReservationConfigsInstanceShapeConfigRepresentation2},
73+
}
74+
75+
CoreComputeCapacityReservationInstanceReservationConfigsRepresentation3 = map[string]interface{}{
76+
"instance_shape": acctest.Representation{RepType: acctest.Required, Create: `VM.Standard.E5.Flex`},
77+
"fault_domain": acctest.Representation{RepType: acctest.Optional, Create: `FAULT-DOMAIN-1`},
78+
"cluster_placement_group_id": acctest.Representation{RepType: acctest.Optional, Create: `${var.cluster_placement_group_id3}`},
79+
"reserved_count": acctest.Representation{RepType: acctest.Required, Create: `1`, Update: `2`},
80+
"instance_shape_config": acctest.RepresentationGroup{RepType: acctest.Required, Group: CoreComputeCapacityReservationInstanceReservationConfigsInstanceShapeConfigRepresentation3},
81+
}
82+
6783
CoreComputeCapacityReservationInstanceReservationConfigsInstanceShapeConfigRepresentation = map[string]interface{}{
6884
"memory_in_gbs": acctest.Representation{RepType: acctest.Optional, Create: `15`},
6985
"ocpus": acctest.Representation{RepType: acctest.Optional, Create: `1`},
7086
}
7187

88+
CoreComputeCapacityReservationInstanceReservationConfigsInstanceShapeConfigRepresentation2 = map[string]interface{}{
89+
"memory_in_gbs": acctest.Representation{RepType: acctest.Required, Create: `24`},
90+
"ocpus": acctest.Representation{RepType: acctest.Required, Create: `2`},
91+
}
92+
93+
CoreComputeCapacityReservationInstanceReservationConfigsInstanceShapeConfigRepresentation3 = map[string]interface{}{
94+
"memory_in_gbs": acctest.Representation{RepType: acctest.Required, Create: `36`},
95+
"ocpus": acctest.Representation{RepType: acctest.Required, Create: `3`},
96+
}
97+
7298
CoreComputeCapacityReservationResourceDependencies = AvailabilityDomainConfig +
7399
DefinedTagsDependencies
74100
)
@@ -114,11 +140,33 @@ func TestCoreComputeCapacityReservationResource_basic(t *testing.T) {
114140
),
115141
},
116142

117-
// Step 1: delete before next Create
143+
// Step 1: Add instance reservation config
144+
{
145+
Config: config + compartmentIdVariableStr + clusterPlacementGroupIdStr + CoreComputeCapacityReservationResourceDependencies +
146+
acctest.GenerateResourceFromRepresentationMap("oci_core_compute_capacity_reservation", "test_compute_capacity_reservation", acctest.Optional, acctest.Update, acctest.RepresentationCopyWithNewProperties(CoreComputeCapacityReservationRepresentation, map[string]interface{}{
147+
"instance_reservation_configs": []acctest.RepresentationGroup{{RepType: acctest.Optional, Group: CoreComputeCapacityReservationInstanceReservationConfigsRepresentation}, {RepType: acctest.Optional, Group: CoreComputeCapacityReservationInstanceReservationConfigsRepresentation2}},
148+
})),
149+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
150+
resource.TestCheckResourceAttr(resourceName, "instance_reservation_configs.#", "2"),
151+
),
152+
},
153+
154+
// Step 2: verify unordered attach
155+
{
156+
Config: config + compartmentIdVariableStr + clusterPlacementGroupIdStr + CoreComputeCapacityReservationResourceDependencies +
157+
acctest.GenerateResourceFromRepresentationMap("oci_core_compute_capacity_reservation", "test_compute_capacity_reservation", acctest.Optional, acctest.Update, acctest.RepresentationCopyWithNewProperties(CoreComputeCapacityReservationRepresentation, map[string]interface{}{
158+
"instance_reservation_configs": []acctest.RepresentationGroup{{RepType: acctest.Optional, Group: CoreComputeCapacityReservationInstanceReservationConfigsRepresentation}, {RepType: acctest.Optional, Group: CoreComputeCapacityReservationInstanceReservationConfigsRepresentation3}, {RepType: acctest.Optional, Group: CoreComputeCapacityReservationInstanceReservationConfigsRepresentation2}},
159+
})),
160+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
161+
resource.TestCheckResourceAttr(resourceName, "instance_reservation_configs.#", "3"),
162+
),
163+
},
164+
165+
// Step 3: delete before next Create
118166
{
119167
Config: config + compartmentIdVariableStr + clusterPlacementGroupIdStr + CoreComputeCapacityReservationResourceDependencies,
120168
},
121-
// Step 2: verify Create with optionals
169+
// Step 4: verify Create with optionals
122170
{
123171
Config: config + compartmentIdVariableStr + clusterPlacementGroupIdStr + CoreComputeCapacityReservationResourceDependencies +
124172
acctest.GenerateResourceFromRepresentationMap("oci_core_compute_capacity_reservation", "test_compute_capacity_reservation", acctest.Optional, acctest.Create, CoreComputeCapacityReservationRepresentation),
@@ -153,7 +201,7 @@ func TestCoreComputeCapacityReservationResource_basic(t *testing.T) {
153201
),
154202
},
155203

156-
// Step 3: verify Update to the compartment (the compartment will be switched back in the next step)
204+
// Step 5: verify Update to the compartment (the compartment will be switched back in the next step)
157205
{
158206
Config: config + compartmentIdVariableStr + compartmentIdUVariableStr + clusterPlacementGroupIdStr + CoreComputeCapacityReservationResourceDependencies +
159207
acctest.GenerateResourceFromRepresentationMap("oci_core_compute_capacity_reservation", "test_compute_capacity_reservation", acctest.Optional, acctest.Create,
@@ -189,7 +237,7 @@ func TestCoreComputeCapacityReservationResource_basic(t *testing.T) {
189237
),
190238
},
191239

192-
// Step 4: verify updates to updatable parameters
240+
// Step 6: verify updates to updatable parameters
193241
{
194242
Config: config + compartmentIdVariableStr + CoreComputeCapacityReservationResourceDependencies + clusterPlacementGroupIdStr +
195243
acctest.GenerateResourceFromRepresentationMap("oci_core_compute_capacity_reservation", "test_compute_capacity_reservation", acctest.Optional, acctest.Update, CoreComputeCapacityReservationRepresentation),
@@ -221,7 +269,7 @@ func TestCoreComputeCapacityReservationResource_basic(t *testing.T) {
221269
},
222270
),
223271
},
224-
// Step 5: verify datasource
272+
// Step 7: verify datasource
225273
{
226274
Config: config +
227275
acctest.GenerateDataSourceFromRepresentationMap("oci_core_compute_capacity_reservations", "test_compute_capacity_reservations", acctest.Optional, acctest.Update, CoreCoreComputeCapacityReservationDataSourceRepresentation) +
@@ -247,7 +295,7 @@ func TestCoreComputeCapacityReservationResource_basic(t *testing.T) {
247295
resource.TestCheckResourceAttrSet(datasourceName, "compute_capacity_reservations.0.used_instance_count"),
248296
),
249297
},
250-
// Step 6: verify singular datasource
298+
// Step 8: verify singular datasource
251299
{
252300
Config: config +
253301
acctest.GenerateDataSourceFromRepresentationMap("oci_core_compute_capacity_reservation", "test_compute_capacity_reservation", acctest.Required, acctest.Create, CoreCoreComputeCapacityReservationSingularDataSourceRepresentation) +

internal/service/core/core_compute_capacity_reservation_resource.go

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
package core
55

66
import (
7+
"bytes"
78
"context"
89
"fmt"
910
"strconv"
1011

1112
"github.com/oracle/terraform-provider-oci/internal/client"
1213
"github.com/oracle/terraform-provider-oci/internal/tfresource"
14+
"github.com/oracle/terraform-provider-oci/internal/utils"
1315

1416
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1517

@@ -60,8 +62,9 @@ func CoreComputeCapacityReservationResource() *schema.Resource {
6062
Elem: schema.TypeString,
6163
},
6264
"instance_reservation_configs": {
63-
Type: schema.TypeList,
65+
Type: schema.TypeSet,
6466
Required: true,
67+
Set: instanceReservationConfigsHashCodeForSets,
6568
MinItems: 1,
6669
Elem: &schema.Resource{
6770
Schema: map[string]*schema.Schema{
@@ -284,10 +287,13 @@ func (s *CoreComputeCapacityReservationResourceCrud) Create() error {
284287
}
285288

286289
if instanceReservationConfigs, ok := s.D.GetOkExists("instance_reservation_configs"); ok {
287-
interfaces := instanceReservationConfigs.([]interface{})
290+
291+
set := instanceReservationConfigs.(*schema.Set)
292+
interfaces := set.List()
293+
288294
tmp := make([]oci_core.InstanceReservationConfigDetails, len(interfaces))
289295
for i := range interfaces {
290-
stateDataIndex := i
296+
stateDataIndex := instanceReservationConfigsHashCodeForSets(interfaces[i])
291297
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "instance_reservation_configs", stateDataIndex)
292298
converted, err := s.mapToInstanceReservationConfigDetails(fieldKeyFormat)
293299
if err != nil {
@@ -382,10 +388,12 @@ func (s *CoreComputeCapacityReservationResourceCrud) Update() error {
382388
}
383389

384390
if instanceReservationConfigs, ok := s.D.GetOkExists("instance_reservation_configs"); ok {
385-
interfaces := instanceReservationConfigs.([]interface{})
391+
set := instanceReservationConfigs.(*schema.Set)
392+
interfaces := set.List()
393+
386394
tmp := make([]oci_core.InstanceReservationConfigDetails, len(interfaces))
387395
for i := range interfaces {
388-
stateDataIndex := i
396+
stateDataIndex := instanceReservationConfigsHashCodeForSets(interfaces[i])
389397
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "instance_reservation_configs", stateDataIndex)
390398
converted, err := s.mapToInstanceReservationConfigDetails(fieldKeyFormat)
391399
if err != nil {
@@ -677,3 +685,53 @@ func (s *CoreComputeCapacityReservationResourceCrud) updateCompartment(compartme
677685
}
678686
return nil
679687
}
688+
689+
func instanceReservationConfigsHashCodeForSets(v interface{}) int {
690+
var buf bytes.Buffer
691+
m := v.(map[string]interface{})
692+
693+
if instanceShape, ok := m["instance_shape"]; ok && instanceShape != "" {
694+
buf.WriteString(fmt.Sprintf("%v-", instanceShape))
695+
}
696+
697+
if reservedCount, ok := m["reserved_count"]; ok && reservedCount != "" {
698+
buf.WriteString(fmt.Sprintf("%v-", reservedCount))
699+
}
700+
701+
if clusterConfig, ok := m["cluster_config"]; ok && clusterConfig != "" {
702+
if clusterConfigList, ok := clusterConfig.([]interface{}); ok && len(clusterConfigList) > 0 {
703+
buf.WriteString("cluster_config-")
704+
for _, clusterConfigMapInterface := range clusterConfigList {
705+
clusterConfigMap := clusterConfigMapInterface.(map[string]interface{})
706+
if hpcIslandIdVal, ok := clusterConfigMap["hpc_island_id"].(string); ok && hpcIslandIdVal != "" {
707+
buf.WriteString(fmt.Sprintf("%v-", hpcIslandIdVal))
708+
}
709+
if networkBlockIdsVal, ok := clusterConfigMap["network_block_ids"]; ok && networkBlockIdsVal != "" {
710+
if networkBlockIdsList, ok := networkBlockIdsVal.([]interface{}); ok && len(networkBlockIdsList) > 0 {
711+
buf.WriteString("network_block_ids-")
712+
for _, networkBlockIdInterface := range networkBlockIdsList {
713+
networkBlockId := networkBlockIdInterface.(string)
714+
buf.WriteString(fmt.Sprintf("%s-", networkBlockId))
715+
}
716+
}
717+
}
718+
}
719+
}
720+
}
721+
722+
if clusterPlacementGroupId, ok := m["cluster_placement_group_id"]; ok && clusterPlacementGroupId != "" {
723+
buf.WriteString(fmt.Sprintf("%v-", clusterPlacementGroupId))
724+
}
725+
726+
if faultDomain, ok := m["fault_domain"]; ok && faultDomain != "" {
727+
buf.WriteString(fmt.Sprintf("%v-", faultDomain))
728+
}
729+
730+
if usedCountInterface, ok := m["used_count"]; ok && usedCountInterface != "" {
731+
if usedCountInt, ok := usedCountInterface.(int); ok && usedCountInt > 0 {
732+
buf.WriteString(fmt.Sprintf("%d-", usedCountInt))
733+
}
734+
}
735+
736+
return utils.GetStringHashcode(buf.String())
737+
}

website/docs/r/core_compute_capacity_reservation.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ The following arguments are supported:
6464
* `defined_tags` - (Optional) (Updatable) Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`
6565
* `display_name` - (Optional) (Updatable) A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
6666
* `freeform_tags` - (Optional) (Updatable) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
67-
* `instance_reservation_configs` - (Optional) (Updatable) The capacity configurations for the capacity reservation.
67+
* `instance_reservation_configs` - (Optional) (Updatable) The capacity configurations for the capacity reservation. (Note: From 6.17.0 instance_reservation_configs field in oci_core_compute_capacity_reservation is changed from TypeList to TypeSet - to avoid unnecessary updates. Also, configs cant by accessed by index)
6868

6969
To use the reservation for the desired shape, specify the shape, count, and optionally the fault domain where you want this configuration.
7070
* `cluster_config` - (Optional) (Updatable) The HPC cluster configuration requested when launching instances in a compute capacity reservation.
@@ -105,7 +105,7 @@ The following attributes are exported:
105105
* `display_name` - A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
106106
* `freeform_tags` - Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
107107
* `id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the compute capacity reservation.
108-
* `instance_reservation_configs` - The capacity configurations for the capacity reservation.
108+
* `instance_reservation_configs` - The capacity configurations for the capacity reservation. (Note: From 6.17.0 instance_reservation_configs field in oci_core_compute_capacity_reservation is changed from TypeList to TypeSet - to avoid unnecessary updates. Also, configs cant by accessed by index)
109109

110110
To use the reservation for the desired shape, specify the shape, count, and optionally the fault domain where you want this configuration.
111111
* `cluster_config` - The HPC cluster configuration requested when launching instances in a compute capacity reservation.

website/docs/r/core_instance_pool.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ The following arguments are supported:
8686
* `instance_configuration_id` - (Required) (Updatable) The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the instance configuration associated with the instance pool.
8787
* `instance_display_name_formatter` - (Optional) (Updatable) A user-friendly formatter for the instance pool's instances. Instance displaynames follow the format. The formatter does not retroactively change instance's displaynames, only instance displaynames in the future follow the format
8888
* `instance_hostname_formatter` - (Optional) (Updatable) A user-friendly formatter for the instance pool's instances. Instance hostnames follow the format. The formatter does not retroactively change instance's hostnames, only instance hostnames in the future follow the format
89-
* `load_balancers` - (Optional) The load balancers to attach to the instance pool. (Note: From 6.14.0 load_balancers field in oci_core_instance_pool is changed from TypeList to TypeSet - to support load balancer insert operation. Also, LB cant by accessed by index)
89+
* `load_balancers` - (Optional) The load balancers to attach to the instance pool. (Note: From 6.16.0 load_balancers field in oci_core_instance_pool is changed from TypeList to TypeSet - to support load balancer insert operation. Also, LB cant by accessed by index)
9090
* `backend_set_name` - (Required) The name of the backend set on the load balancer to add instances to.
9191
* `load_balancer_id` - (Required) The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the load balancer to attach to the instance pool.
9292
* `port` - (Required) The port value to use when creating the backend set.
@@ -135,7 +135,7 @@ The following attributes are exported:
135135
* `instance_configuration_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the instance configuration associated with the instance pool.
136136
* `instance_display_name_formatter` - A user-friendly formatter for the instance pool's instances. Instance displaynames follow the format. The formatter does not retroactively change instance's displaynames, only instance displaynames in the future follow the format
137137
* `instance_hostname_formatter` - A user-friendly formatter for the instance pool's instances. Instance hostnames follow the format. The formatter does not retroactively change instance's hostnames, only instance hostnames in the future follow the format
138-
* `load_balancers` - The load balancers attached to the instance pool. (Note: From 6.14.0 load_balancers field in oci_core_instance_pool is changed from TypeList to TypeSet - to support load balancer insert operation. Also, LB cant by accessed by index)
138+
* `load_balancers` - The load balancers attached to the instance pool. (Note: From 6.16.0 load_balancers field in oci_core_instance_pool is changed from TypeList to TypeSet - to support load balancer insert operation. Also, LB cant by accessed by index)
139139
* `backend_set_name` - The name of the backend set on the load balancer.
140140
* `id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the load balancer attachment.
141141
* `instance_pool_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the instance pool of the load balancer attachment.

0 commit comments

Comments
 (0)