Skip to content

Commit b49717f

Browse files
committed
Merge branch 'main' into f-iter-funcs
2 parents f2f3c8a + 7ba5b3b commit b49717f

20 files changed

+993
-651
lines changed

.changelog/44389.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_dms_endpoint: Ensure that `postgres_settings` are updated
3+
```

.changelog/44417.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/aws_opensearch_domain: Add `aiml_options` argument
3+
```

internal/service/dms/endpoint.go

Lines changed: 112 additions & 113 deletions
Large diffs are not rendered by default.

internal/service/dms/endpoint_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,67 @@ func TestAccDMSEndpoint_PostgreSQL_settings_target(t *testing.T) {
12101210
})
12111211
}
12121212

1213+
func TestAccDMSEndpoint_PostgreSQL_settings_update(t *testing.T) {
1214+
ctx := acctest.Context(t)
1215+
resourceName := "aws_dms_endpoint.test"
1216+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
1217+
1218+
resource.ParallelTest(t, resource.TestCase{
1219+
PreCheck: func() { acctest.PreCheck(ctx, t) },
1220+
ErrorCheck: acctest.ErrorCheck(t, names.DMSServiceID),
1221+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
1222+
CheckDestroy: testAccCheckEndpointDestroy(ctx),
1223+
Steps: []resource.TestStep{
1224+
{
1225+
// Create with heartbeat disabled
1226+
Config: testAccEndpointConfig_postgreSQLHeartbeat(rName, false, ""),
1227+
Check: resource.ComposeAggregateTestCheckFunc(
1228+
testAccCheckEndpointExists(ctx, resourceName),
1229+
resource.TestCheckResourceAttr(resourceName, "engine_name", "postgres"),
1230+
resource.TestCheckResourceAttr(resourceName, "postgres_settings.0.heartbeat_enable", acctest.CtFalse),
1231+
),
1232+
},
1233+
{
1234+
// Update only nested postgres_settings: enable heartbeat + set schema
1235+
Config: testAccEndpointConfig_postgreSQLHeartbeat(rName, true, "dms_heartbeat"),
1236+
Check: resource.ComposeAggregateTestCheckFunc(
1237+
testAccCheckEndpointExists(ctx, resourceName),
1238+
resource.TestCheckResourceAttr(resourceName, "postgres_settings.0.heartbeat_enable", acctest.CtTrue),
1239+
resource.TestCheckResourceAttr(resourceName, "postgres_settings.0.heartbeat_schema", "dms_heartbeat"),
1240+
),
1241+
},
1242+
},
1243+
})
1244+
}
1245+
1246+
func testAccEndpointConfig_postgreSQLHeartbeat(id string, heartbeat bool, schema string) string {
1247+
schemaLine := ""
1248+
if schema != "" {
1249+
schemaLine = fmt.Sprintf(`heartbeat_schema = %q`, schema)
1250+
}
1251+
1252+
// DMS ModifyEndpoint accepts metadata changes without validating connectivity,
1253+
// so placeholder connection values are sufficient for the test
1254+
return fmt.Sprintf(`
1255+
resource "aws_dms_endpoint" "test" {
1256+
endpoint_id = %q
1257+
endpoint_type = "source"
1258+
engine_name = "postgres"
1259+
1260+
username = "user"
1261+
password = "pass"
1262+
server_name = "example.com"
1263+
database_name = "postgres"
1264+
port = 5432
1265+
1266+
postgres_settings {
1267+
heartbeat_enable = %t
1268+
%s
1269+
}
1270+
}
1271+
`, id, heartbeat, schemaLine)
1272+
}
1273+
12131274
func TestAccDMSEndpoint_SQLServer_basic(t *testing.T) {
12141275
ctx := acctest.Context(t)
12151276
resourceName := "aws_dms_endpoint.test"

internal/service/ec2/ebs_volume_attachment.go

Lines changed: 0 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,19 @@ package ec2
66
import (
77
"bytes"
88
"context"
9-
"errors"
109
"fmt"
1110
"log"
1211
"strings"
1312
"time"
1413

1514
"github.com/aws/aws-sdk-go-v2/aws"
1615
"github.com/aws/aws-sdk-go-v2/service/ec2"
17-
awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types"
1816
"github.com/hashicorp/aws-sdk-go-base/v2/tfawserr"
1917
"github.com/hashicorp/terraform-plugin-log/tflog"
2018
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
21-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
2219
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2320
"github.com/hashicorp/terraform-provider-aws/internal/conns"
2421
"github.com/hashicorp/terraform-provider-aws/internal/create"
25-
"github.com/hashicorp/terraform-provider-aws/internal/enum"
2622
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
2723
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
2824
"github.com/hashicorp/terraform-provider-aws/names"
@@ -208,48 +204,6 @@ func volumeAttachmentID(name, volumeID, instanceID string) string {
208204
return fmt.Sprintf("vai-%d", create.StringHashcode(buf.String()))
209205
}
210206

211-
func findVolumeAttachment(ctx context.Context, conn *ec2.Client, volumeID, instanceID, deviceName string) (*awstypes.VolumeAttachment, error) {
212-
input := ec2.DescribeVolumesInput{
213-
Filters: newAttributeFilterList(map[string]string{
214-
"attachment.device": deviceName,
215-
"attachment.instance-id": instanceID,
216-
}),
217-
VolumeIds: []string{volumeID},
218-
}
219-
220-
output, err := findEBSVolume(ctx, conn, &input)
221-
222-
if err != nil {
223-
return nil, err
224-
}
225-
226-
if state := output.State; state == awstypes.VolumeStateAvailable || state == awstypes.VolumeStateDeleted {
227-
return nil, &retry.NotFoundError{
228-
Message: string(state),
229-
LastRequest: input,
230-
}
231-
}
232-
233-
// Eventual consistency check.
234-
if aws.ToString(output.VolumeId) != volumeID {
235-
return nil, &retry.NotFoundError{
236-
LastRequest: input,
237-
}
238-
}
239-
240-
for _, v := range output.Attachments {
241-
if v.State == awstypes.VolumeAttachmentStateDetached {
242-
continue
243-
}
244-
245-
if aws.ToString(v.Device) == deviceName && aws.ToString(v.InstanceId) == instanceID {
246-
return &v, nil
247-
}
248-
}
249-
250-
return nil, &retry.NotFoundError{}
251-
}
252-
253207
func stopVolumeAttachmentInstance(ctx context.Context, conn *ec2.Client, id string, force bool, timeout time.Duration) error {
254208
tflog.Info(ctx, "Stopping EC2 Instance", map[string]any{
255209
"ec2_instance_id": id,
@@ -271,92 +225,3 @@ func stopVolumeAttachmentInstance(ctx context.Context, conn *ec2.Client, id stri
271225

272226
return nil
273227
}
274-
275-
func waitVolumeAttachmentInstanceStopped(ctx context.Context, conn *ec2.Client, id string, timeout time.Duration) (*awstypes.Instance, error) {
276-
stateConf := &retry.StateChangeConf{
277-
Pending: enum.Slice(
278-
awstypes.InstanceStateNamePending,
279-
awstypes.InstanceStateNameRunning,
280-
awstypes.InstanceStateNameShuttingDown,
281-
awstypes.InstanceStateNameStopping,
282-
),
283-
Target: enum.Slice(awstypes.InstanceStateNameStopped),
284-
Refresh: statusVolumeAttachmentInstanceState(ctx, conn, id),
285-
Timeout: timeout,
286-
Delay: 10 * time.Second,
287-
MinTimeout: 3 * time.Second,
288-
}
289-
290-
outputRaw, err := stateConf.WaitForStateContext(ctx)
291-
292-
if output, ok := outputRaw.(*awstypes.Instance); ok {
293-
if stateReason := output.StateReason; stateReason != nil {
294-
tfresource.SetLastError(err, errors.New(aws.ToString(stateReason.Message)))
295-
}
296-
297-
return output, err
298-
}
299-
300-
return nil, err
301-
}
302-
303-
func waitVolumeAttachmentInstanceReady(ctx context.Context, conn *ec2.Client, id string, timeout time.Duration) (*awstypes.Instance, error) {
304-
stateConf := &retry.StateChangeConf{
305-
Pending: enum.Slice(awstypes.InstanceStateNamePending, awstypes.InstanceStateNameStopping),
306-
Target: enum.Slice(awstypes.InstanceStateNameRunning, awstypes.InstanceStateNameStopped),
307-
Refresh: statusVolumeAttachmentInstanceState(ctx, conn, id),
308-
Timeout: timeout,
309-
Delay: 10 * time.Second,
310-
MinTimeout: 3 * time.Second,
311-
}
312-
313-
outputRaw, err := stateConf.WaitForStateContext(ctx)
314-
315-
if output, ok := outputRaw.(*awstypes.Instance); ok {
316-
if stateReason := output.StateReason; stateReason != nil {
317-
tfresource.SetLastError(err, errors.New(aws.ToString(stateReason.Message)))
318-
}
319-
320-
return output, err
321-
}
322-
323-
return nil, err
324-
}
325-
326-
func waitVolumeAttachmentDeleted(ctx context.Context, conn *ec2.Client, volumeID, instanceID, deviceName string, timeout time.Duration) (*awstypes.VolumeAttachment, error) {
327-
stateConf := &retry.StateChangeConf{
328-
Pending: enum.Slice(awstypes.VolumeAttachmentStateDetaching),
329-
Target: []string{},
330-
Refresh: statusVolumeAttachment(ctx, conn, volumeID, instanceID, deviceName),
331-
Timeout: timeout,
332-
Delay: 10 * time.Second,
333-
MinTimeout: 3 * time.Second,
334-
}
335-
336-
outputRaw, err := stateConf.WaitForStateContext(ctx)
337-
338-
if output, ok := outputRaw.(*awstypes.VolumeAttachment); ok {
339-
return output, err
340-
}
341-
342-
return nil, err
343-
}
344-
345-
func statusVolumeAttachmentInstanceState(ctx context.Context, conn *ec2.Client, id string) retry.StateRefreshFunc {
346-
return func() (any, string, error) {
347-
// Don't call FindInstanceByID as it maps useful status codes to NotFoundError.
348-
output, err := findInstance(ctx, conn, &ec2.DescribeInstancesInput{
349-
InstanceIds: []string{id},
350-
})
351-
352-
if tfresource.NotFound(err) {
353-
return nil, "", nil
354-
}
355-
356-
if err != nil {
357-
return nil, "", err
358-
}
359-
360-
return output, string(output.State.Name), nil
361-
}
362-
}

internal/service/ec2/ec2_eip.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ import (
1616
awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types"
1717
"github.com/hashicorp/aws-sdk-go-base/v2/tfawserr"
1818
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
19-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
2019
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2120
"github.com/hashicorp/terraform-provider-aws/internal/conns"
2221
"github.com/hashicorp/terraform-provider-aws/internal/enum"
2322
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
24-
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
2523
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
2624
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
2725
"github.com/hashicorp/terraform-provider-aws/names"
@@ -339,7 +337,7 @@ func resourceEIPDelete(ctx context.Context, d *schema.ResourceData, meta any) di
339337
timeout = 10 * time.Minute // IPAM eventual consistency
340338
)
341339
_, err := tfresource.RetryUntilNotFound(ctx, timeout, func(ctx context.Context) (any, error) {
342-
return findIPAMPoolAllocationsForEIP(ctx, conn, ipamPoolID, d.Get("allocation_id").(string))
340+
return findIPAMPoolAllocationForResource(ctx, conn, ipamPoolID, d.Get("allocation_id").(string))
343341
})
344342

345343
if err != nil {
@@ -430,25 +428,3 @@ func disassociateEIP(ctx context.Context, conn *ec2.Client, associationID string
430428
func eipARN(ctx context.Context, c *conns.AWSClient, allocationID string) string {
431429
return c.RegionalARN(ctx, names.EC2, "elastic-ip/"+allocationID)
432430
}
433-
434-
func findIPAMPoolAllocationsForEIP(ctx context.Context, conn *ec2.Client, ipamPoolID, eipAllocationID string) ([]awstypes.IpamPoolAllocation, error) {
435-
input := ec2.GetIpamPoolAllocationsInput{
436-
IpamPoolId: aws.String(ipamPoolID),
437-
}
438-
439-
output, err := findIPAMPoolAllocations(ctx, conn, &input)
440-
441-
if err != nil {
442-
return nil, err
443-
}
444-
445-
output = tfslices.Filter(output, func(v awstypes.IpamPoolAllocation) bool {
446-
return v.ResourceType == awstypes.IpamPoolAllocationResourceTypeEip && aws.ToString(v.ResourceId) == eipAllocationID
447-
})
448-
449-
if len(output) == 0 {
450-
return nil, &retry.NotFoundError{}
451-
}
452-
453-
return output, nil
454-
}

0 commit comments

Comments
 (0)