Skip to content

Commit 7739b13

Browse files
authored
Merge pull request #44498 from oracle-community/fix-issue-44480
odb/aws_odb_cloud_vm_cluster: fixes issue with `data_storage_size_in_tbs`
2 parents 71dfd7f + 1332fdf commit 7739b13

File tree

5 files changed

+232
-45
lines changed

5 files changed

+232
-45
lines changed

.changelog/44498.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/aws_odb_cloud_vm_cluster : Fixed planmodifier for data_storage_size_in_tbs. Marked it mandatory. Fixed gi-version issue during creation
3+
```

internal/service/odb/cloud_vm_cluster.go

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import (
99
"strings"
1010
"time"
1111

12+
"github.com/YakDriver/regexache"
1213
"github.com/aws/aws-sdk-go-v2/aws"
1314
"github.com/aws/aws-sdk-go-v2/service/odb"
1415
odbtypes "github.com/aws/aws-sdk-go-v2/service/odb/types"
1516
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
1617
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
1718
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
19+
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
1820
"github.com/hashicorp/terraform-plugin-framework/path"
1921
"github.com/hashicorp/terraform-plugin-framework/resource"
2022
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -55,6 +57,7 @@ func newResourceCloudVmCluster(_ context.Context) (resource.ResourceWithConfigur
5557

5658
const (
5759
ResNameCloudVmCluster = "Cloud Vm Cluster"
60+
MajorGiVersionPattern = `^\d+\.0\.0\.0$`
5861
)
5962

6063
var ResourceCloudVmCluster = newResourceCloudVmCluster
@@ -70,6 +73,9 @@ func (r *resourceCloudVmCluster) Schema(ctx context.Context, req resource.Schema
7073
licenseModelType := fwtypes.StringEnumType[odbtypes.LicenseModel]()
7174
diskRedundancyType := fwtypes.StringEnumType[odbtypes.DiskRedundancy]()
7275
computeModelType := fwtypes.StringEnumType[odbtypes.ComputeModel]()
76+
giVersionValidator := []validator.String{
77+
stringvalidator.RegexMatches(regexache.MustCompile(MajorGiVersionPattern), "Gi version must be of the format 19.0.0.0"),
78+
}
7379
resp.Schema = schema.Schema{
7480
Attributes: map[string]schema.Attribute{
7581
names.AttrARN: framework.ARNAttributeComputedOnly(),
@@ -98,11 +104,9 @@ func (r *resourceCloudVmCluster) Schema(ctx context.Context, req resource.Schema
98104
Description: "The number of CPU cores to enable on the VM cluster. Changing this will create a new resource.",
99105
},
100106
"data_storage_size_in_tbs": schema.Float64Attribute{
101-
Optional: true,
102-
Computed: true,
107+
Required: true,
103108
PlanModifiers: []planmodifier.Float64{
104109
float64planmodifier.RequiresReplace(),
105-
float64planmodifier.UseStateForUnknown(),
106110
},
107111
Description: "The size of the data disk group, in terabytes (TBs), to allocate for the VM cluster. Changing this will create a new resource.",
108112
},
@@ -151,8 +155,18 @@ func (r *resourceCloudVmCluster) Schema(ctx context.Context, req resource.Schema
151155
PlanModifiers: []planmodifier.String{
152156
stringplanmodifier.RequiresReplace(),
153157
},
158+
//Note: underlying API only accepts major gi_version.
159+
Validators: giVersionValidator,
154160
Description: "A valid software version of Oracle Grid Infrastructure (GI). To get the list of valid values, use the ListGiVersions operation and specify the shape of the Exadata infrastructure. Example: 19.0.0.0 This member is required. Changing this will create a new resource.",
155161
},
162+
//Underlying API returns complete gi version. For example if gi_version 23.0.0.0 then underlying api returns a version starting with 23
163+
"gi_version_computed": schema.StringAttribute{
164+
Computed: true,
165+
PlanModifiers: []planmodifier.String{
166+
stringplanmodifier.UseStateForUnknown(),
167+
},
168+
Description: "A complete software version of Oracle Grid Infrastructure (GI).",
169+
},
156170
//Underlying API treats Hostname as hostname prefix. Therefore, explicitly setting it. API also returns new hostname prefix by appending the input hostname
157171
//prefix. Therefore, we have hostname_prefix and hostname_prefix_computed
158172
"hostname_prefix_computed": schema.StringAttribute{
@@ -475,7 +489,17 @@ func (r *resourceCloudVmCluster) Create(ctx context.Context, req resource.Create
475489
plan.HostnamePrefix = types.StringValue(hostnamePrefix)
476490
plan.HostnamePrefixComputed = types.StringValue(*createdVmCluster.Hostname)
477491
//scan listener port not returned by API directly
478-
plan.ScanListenerPortTcp = types.Int32PointerValue(createdVmCluster.ListenerPort)
492+
plan.ScanListenerPortTcp = flex.Int32ToFramework(ctx, createdVmCluster.ListenerPort)
493+
plan.GiVersionComputed = flex.StringToFramework(ctx, createdVmCluster.GiVersion)
494+
giVersionMajor, err := getMajorGiVersion(createdVmCluster.GiVersion)
495+
if err != nil {
496+
resp.Diagnostics.AddError(
497+
create.ProblemStandardMessage(names.ODB, create.ErrActionWaitingForCreation, ResNameCloudVmCluster, plan.DisplayName.ValueString(), err),
498+
err.Error(),
499+
)
500+
return
501+
}
502+
plan.GiVersion = flex.StringToFramework(ctx, giVersionMajor)
479503
resp.Diagnostics.Append(flex.Flatten(ctx, createdVmCluster, &plan)...)
480504
if resp.Diagnostics.HasError() {
481505
return
@@ -508,8 +532,17 @@ func (r *resourceCloudVmCluster) Read(ctx context.Context, req resource.ReadRequ
508532
state.HostnamePrefix = types.StringValue(hostnamePrefix)
509533
state.HostnamePrefixComputed = types.StringValue(*out.Hostname)
510534
//scan listener port not returned by API directly
511-
state.ScanListenerPortTcp = types.Int32PointerValue(out.ListenerPort)
512-
535+
state.ScanListenerPortTcp = flex.Int32ToFramework(ctx, out.ListenerPort)
536+
state.GiVersionComputed = flex.StringToFramework(ctx, out.GiVersion)
537+
giVersionMajor, err := getMajorGiVersion(out.GiVersion)
538+
if err != nil {
539+
resp.Diagnostics.AddError(
540+
create.ProblemStandardMessage(names.ODB, create.ErrActionWaitingForCreation, ResNameCloudVmCluster, state.CloudVmClusterId.ValueString(), err),
541+
err.Error(),
542+
)
543+
return
544+
}
545+
state.GiVersion = flex.StringToFramework(ctx, giVersionMajor)
513546
resp.Diagnostics.Append(flex.Flatten(ctx, out, &state)...)
514547
if resp.Diagnostics.HasError() {
515548
return
@@ -620,6 +653,16 @@ func FindCloudVmClusterForResourceByID(ctx context.Context, conn *odb.Client, id
620653
}
621654
return out.CloudVmCluster, nil
622655
}
656+
func getMajorGiVersion(giVersionComputed *string) (*string, error) {
657+
giVersionMajor := strings.Split(*giVersionComputed, ".")[0]
658+
giVersionMajor = giVersionMajor + ".0.0.0"
659+
regxGiVersionMajor := regexache.MustCompile(MajorGiVersionPattern)
660+
if !regxGiVersionMajor.MatchString(giVersionMajor) {
661+
err := errors.New("gi_version major retrieved from gi_version_computed does not match the pattern 19.0.0.0")
662+
return nil, err
663+
}
664+
return &giVersionMajor, nil
665+
}
623666

624667
type cloudVmClusterResourceModel struct {
625668
framework.WithRegionModel
@@ -635,7 +678,8 @@ type cloudVmClusterResourceModel struct {
635678
DiskRedundancy fwtypes.StringEnum[odbtypes.DiskRedundancy] `tfsdk:"disk_redundancy"`
636679
DisplayName types.String `tfsdk:"display_name"`
637680
Domain types.String `tfsdk:"domain"`
638-
GiVersion types.String `tfsdk:"gi_version"`
681+
GiVersion types.String `tfsdk:"gi_version" autoflex:",noflatten"`
682+
GiVersionComputed types.String `tfsdk:"gi_version_computed" autoflex:",noflatten"`
639683
HostnamePrefixComputed types.String `tfsdk:"hostname_prefix_computed" autoflex:",noflatten"`
640684
HostnamePrefix types.String `tfsdk:"hostname_prefix" autoflex:"-"`
641685
IormConfigCache fwtypes.ListNestedObjectValueOf[cloudVMCExadataIormConfigResourceModel] `tfsdk:"iorm_config_cache"`

0 commit comments

Comments
 (0)