Skip to content

Commit e242745

Browse files
committed
scan-listener-port computation added
1 parent 38ff7d1 commit e242745

File tree

3 files changed

+22
-51
lines changed

3 files changed

+22
-51
lines changed

internal/service/odb/cloud_vm_cluster.go

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,26 @@ package odb
55
import (
66
"context"
77
"errors"
8-
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
9-
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
10-
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier"
11-
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
128
"strings"
139
"time"
1410

1511
"github.com/aws/aws-sdk-go-v2/aws"
1612
"github.com/aws/aws-sdk-go-v2/service/odb"
1713
odbtypes "github.com/aws/aws-sdk-go-v2/service/odb/types"
1814
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
15+
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
16+
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
17+
"github.com/hashicorp/terraform-plugin-framework/path"
1918
"github.com/hashicorp/terraform-plugin-framework/resource"
2019
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
2120
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
2221
"github.com/hashicorp/terraform-plugin-framework/resource/schema/float64planmodifier"
2322
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int32planmodifier"
23+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier"
2424
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
2525
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier"
2626
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
27+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
2728
"github.com/hashicorp/terraform-plugin-framework/types"
2829
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
2930
"github.com/hashicorp/terraform-provider-aws/internal/create"
@@ -59,6 +60,7 @@ var ResourceCloudVmCluster = newResourceCloudVmCluster
5960
type resourceCloudVmCluster struct {
6061
framework.ResourceWithModel[cloudVmClusterResourceModel]
6162
framework.WithTimeouts
63+
framework.WithImportByID
6264
}
6365

6466
func (r *resourceCloudVmCluster) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
@@ -391,6 +393,7 @@ func (r *resourceCloudVmCluster) Create(ctx context.Context, req resource.Create
391393

392394
createTimeout := r.CreateTimeout(ctx, plan.Timeouts)
393395
createdVmCluster, err := waitCloudVmClusterCreated(ctx, conn, *out.CloudVmClusterId, createTimeout)
396+
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root(names.AttrID), aws.ToString(out.CloudVmClusterId))...)
394397
if err != nil {
395398
resp.Diagnostics.AddError(
396399
create.ProblemStandardMessage(names.ODB, create.ErrActionWaitingForCreation, ResNameCloudVmCluster, plan.DisplayName.ValueString(), err),
@@ -401,6 +404,8 @@ func (r *resourceCloudVmCluster) Create(ctx context.Context, req resource.Create
401404
hostnamePrefix := strings.Split(*input.Hostname, "-")[0]
402405
plan.HostnamePrefix = types.StringValue(hostnamePrefix)
403406
plan.HostnamePrefixComputed = types.StringValue(*createdVmCluster.Hostname)
407+
//scan listener port not returned by API directly
408+
plan.ScanListenerPortTcp = types.Int32PointerValue(createdVmCluster.ListenerPort)
404409
resp.Diagnostics.Append(flex.Flatten(ctx, createdVmCluster, &plan)...)
405410
if resp.Diagnostics.HasError() {
406411
return
@@ -432,8 +437,10 @@ func (r *resourceCloudVmCluster) Read(ctx context.Context, req resource.ReadRequ
432437
hostnamePrefix := strings.Split(*out.Hostname, "-")[0]
433438
state.HostnamePrefix = types.StringValue(hostnamePrefix)
434439
state.HostnamePrefixComputed = types.StringValue(*out.Hostname)
435-
resp.Diagnostics.Append(flex.Flatten(ctx, out, &state)...)
440+
//scan listener port not returned by API directly
441+
state.ScanListenerPortTcp = types.Int32PointerValue(out.ListenerPort)
436442

443+
resp.Diagnostics.Append(flex.Flatten(ctx, out, &state)...)
437444
if resp.Diagnostics.HasError() {
438445
return
439446
}
@@ -492,24 +499,6 @@ func waitCloudVmClusterCreated(ctx context.Context, conn *odb.Client, id string,
492499
return nil, err
493500
}
494501

495-
func waitCloudVmClusterUpdated(ctx context.Context, conn *odb.Client, id string, timeout time.Duration) (*odbtypes.CloudVmCluster, error) {
496-
stateConf := &retry.StateChangeConf{
497-
Pending: enum.Slice(odbtypes.ResourceStatusUpdating),
498-
Target: enum.Slice(odbtypes.ResourceStatusAvailable, odbtypes.ResourceStatusFailed),
499-
Refresh: statusCloudVmCluster(ctx, conn, id),
500-
Timeout: timeout,
501-
NotFoundChecks: 20,
502-
ContinuousTargetOccurence: 2,
503-
}
504-
505-
outputRaw, err := stateConf.WaitForStateContext(ctx)
506-
if out, ok := outputRaw.(*odbtypes.CloudVmCluster); ok {
507-
return out, err
508-
}
509-
510-
return nil, err
511-
}
512-
513502
func waitCloudVmClusterDeleted(ctx context.Context, conn *odb.Client, id string, timeout time.Duration) (*odbtypes.CloudVmCluster, error) {
514503
stateConf := &retry.StateChangeConf{
515504
Pending: enum.Slice(odbtypes.ResourceStatusTerminating),
@@ -545,7 +534,6 @@ func FindCloudVmClusterForResourceByID(ctx context.Context, conn *odb.Client, id
545534
input := odb.GetCloudVmClusterInput{
546535
CloudVmClusterId: aws.String(id),
547536
}
548-
549537
out, err := conn.GetCloudVmCluster(ctx, &input)
550538
if err != nil {
551539
if errs.IsA[*odbtypes.ResourceNotFoundException](err) {
@@ -554,7 +542,6 @@ func FindCloudVmClusterForResourceByID(ctx context.Context, conn *odb.Client, id
554542
LastRequest: &input,
555543
}
556544
}
557-
558545
return nil, err
559546
}
560547

@@ -608,7 +595,7 @@ type cloudVmClusterResourceModel struct {
608595
VipIds fwtypes.ListValueOf[types.String] `tfsdk:"vip_ids"`
609596
CreatedAt timetypes.RFC3339 `tfsdk:"created_at"`
610597
ComputeModel fwtypes.StringEnum[odbtypes.ComputeModel] `tfsdk:"compute_model"`
611-
ScanListenerPortTcp types.Int32 `tfsdk:"scan_listener_port_tcp"`
598+
ScanListenerPortTcp types.Int32 `tfsdk:"scan_listener_port_tcp" autoflex:",noflatten"`
612599
Tags tftags.Map `tfsdk:"tags"`
613600
TagsAll tftags.Map `tfsdk:"tags_all"`
614601
}

internal/service/odb/cloud_vm_cluster_data_source_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ resource "aws_odb_cloud_vm_cluster" "test" {
171171
db_servers = [for db_server in data.aws_odb_db_servers_list.test.db_servers : db_server.id]
172172
db_node_storage_size_in_gbs = 120.0
173173
memory_size_in_gbs = 60
174+
data_collection_options {
175+
is_diagnostics_events_enabled = false
176+
is_health_monitoring_enabled = false
177+
is_incident_logs_enabled = false
178+
}
174179
tags = {
175180
"env" = "dev"
176181
}

internal/service/odb/cloud_vm_cluster_test.go

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ func TestAccODBCloudVmCluster_taggingTest(t *testing.T) {
115115
}
116116
var cloudvmcluster1 odbtypes.CloudVmCluster
117117
var cloudvmcluster2 odbtypes.CloudVmCluster
118-
var cloudvmcluster3 odbtypes.CloudVmCluster
119118
vmcDisplayName := sdkacctest.RandomWithPrefix(vmClusterTestEntity.vmClusterDisplayNamePrefix)
120119
resourceName := "aws_odb_cloud_vm_cluster.test"
121120

@@ -140,8 +139,6 @@ func TestAccODBCloudVmCluster_taggingTest(t *testing.T) {
140139
return nil
141140
}),
142141
vmClusterTestEntity.testAccCheckCloudVmClusterExists(ctx, resourceName, &cloudvmcluster1),
143-
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"),
144-
resource.TestCheckResourceAttr(resourceName, "tags.env", "dev"),
145142
),
146143
},
147144
{
@@ -169,26 +166,6 @@ func TestAccODBCloudVmCluster_taggingTest(t *testing.T) {
169166
ImportState: true,
170167
ImportStateVerify: true,
171168
},
172-
{
173-
Config: vmClusterTestEntity.testAccCloudVmClusterConfigBasic(vmcDisplayName, publicKey),
174-
Check: resource.ComposeAggregateTestCheckFunc(
175-
vmClusterTestEntity.testAccCheckCloudVmClusterExists(ctx, resourceName, &cloudvmcluster3),
176-
resource.ComposeTestCheckFunc(func(state *terraform.State) error {
177-
if strings.Compare(*(cloudvmcluster1.CloudVmClusterId), *(cloudvmcluster3.CloudVmClusterId)) != 0 {
178-
return errors.New("Should not create a new cloud vm cluster for tag update")
179-
}
180-
return nil
181-
}),
182-
183-
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"),
184-
resource.TestCheckResourceAttr(resourceName, "tags.env", "dev"),
185-
),
186-
},
187-
{
188-
ResourceName: resourceName,
189-
ImportState: true,
190-
ImportStateVerify: true,
191-
},
192169
},
193170
})
194171
}
@@ -308,8 +285,10 @@ resource "aws_odb_cloud_vm_cluster" "test" {
308285
db_servers = [for db_server in data.aws_odb_db_servers_list.test.db_servers : db_server.id]
309286
db_node_storage_size_in_gbs = 120.0
310287
memory_size_in_gbs = 60
311-
tags = {
312-
"env" = "dev"
288+
data_collection_options {
289+
is_diagnostics_events_enabled = false
290+
is_health_monitoring_enabled = false
291+
is_incident_logs_enabled = false
313292
}
314293
315294
}

0 commit comments

Comments
 (0)