From f6993ec2f304e7e469b5b415dbd967e95cad1c66 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 22 Jan 2024 15:53:14 -0500 Subject: [PATCH 1/4] vpc/eni_sg_attach: Add configurable timeouts --- .../vpc_network_interface_sg_attachment.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/service/ec2/vpc_network_interface_sg_attachment.go b/internal/service/ec2/vpc_network_interface_sg_attachment.go index 3e95eec051a..b776e9fa67f 100644 --- a/internal/service/ec2/vpc_network_interface_sg_attachment.go +++ b/internal/service/ec2/vpc_network_interface_sg_attachment.go @@ -8,6 +8,7 @@ import ( "fmt" "log" "strings" + "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" @@ -25,10 +26,18 @@ func ResourceNetworkInterfaceSGAttachment() *schema.Resource { CreateWithoutTimeout: resourceNetworkInterfaceSGAttachmentCreate, ReadWithoutTimeout: resourceNetworkInterfaceSGAttachmentRead, DeleteWithoutTimeout: resourceNetworkInterfaceSGAttachmentDelete, + Importer: &schema.ResourceImporter{ StateContext: resourceNetworkInterfaceSGAttachmentImport, }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(3 * time.Minute), + Read: schema.DefaultTimeout(3 * time.Minute), + Update: schema.DefaultTimeout(3 * time.Minute), + Delete: schema.DefaultTimeout(3 * time.Minute), + }, + Schema: map[string]*schema.Schema{ "network_interface_id": { Type: schema.TypeString, @@ -99,7 +108,7 @@ func resourceNetworkInterfaceSGAttachmentRead(ctx context.Context, d *schema.Res networkInterfaceID := d.Get("network_interface_id").(string) sgID := d.Get("security_group_id").(string) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (interface{}, error) { + outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, maxDuration(ec2PropagationTimeout, d.Timeout(schema.TimeoutRead)), func() (interface{}, error) { return FindNetworkInterfaceSecurityGroup(ctx, conn, networkInterfaceID, sgID) }, d.IsNewResource()) @@ -121,6 +130,14 @@ func resourceNetworkInterfaceSGAttachmentRead(ctx context.Context, d *schema.Res return diags } +func maxDuration(a, b time.Duration) time.Duration { + if a >= b { + return a + } + + return b +} + func resourceNetworkInterfaceSGAttachmentDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).EC2Conn(ctx) From dd03a994077971f0430679fc4cf3d4238da4de72 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 22 Jan 2024 15:53:58 -0500 Subject: [PATCH 2/4] vpc/eni_sg_attach: Update documentation --- .../docs/r/network_interface_sg_attachment.html.markdown | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/website/docs/r/network_interface_sg_attachment.html.markdown b/website/docs/r/network_interface_sg_attachment.html.markdown index 43042fd34f0..a2e5a85a4bc 100644 --- a/website/docs/r/network_interface_sg_attachment.html.markdown +++ b/website/docs/r/network_interface_sg_attachment.html.markdown @@ -93,6 +93,15 @@ resource "aws_network_interface_sg_attachment" "sg_attachment" { This resource exports no additional attributes. +## Timeouts + +[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts): + +- `create` - (Default `3m`) +- `read` - (Default `3m`) +- `update` - (Default `3m`) +- `delete` - (Default `3m`) + ## Import In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Network Interface Security Group attachments using the associated network interface ID and security group ID, separated by an underscore (`_`). For example: From 28658e0c62970216ebccdb5af481131f6236c25b Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 22 Jan 2024 15:56:15 -0500 Subject: [PATCH 3/4] Add changelog --- .changelog/35435.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/35435.txt diff --git a/.changelog/35435.txt b/.changelog/35435.txt new file mode 100644 index 00000000000..c15f8e2ae5d --- /dev/null +++ b/.changelog/35435.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_network_interface_sg_attachment: Increase default timeouts to 3 minutes and allow them to be configured +``` \ No newline at end of file From cf354c515180bbf1692f2a26e276b81d23aba338 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 22 Jan 2024 16:10:27 -0500 Subject: [PATCH 4/4] eni_sg_attachment: No update, no update timeout --- .../service/ec2/vpc_network_interface_sg_attachment.go | 1 - .../ec2/vpc_network_interface_sg_attachment_test.go | 8 ++++---- .../docs/r/network_interface_sg_attachment.html.markdown | 1 - 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/service/ec2/vpc_network_interface_sg_attachment.go b/internal/service/ec2/vpc_network_interface_sg_attachment.go index b776e9fa67f..3792e30cef6 100644 --- a/internal/service/ec2/vpc_network_interface_sg_attachment.go +++ b/internal/service/ec2/vpc_network_interface_sg_attachment.go @@ -34,7 +34,6 @@ func ResourceNetworkInterfaceSGAttachment() *schema.Resource { Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(3 * time.Minute), Read: schema.DefaultTimeout(3 * time.Minute), - Update: schema.DefaultTimeout(3 * time.Minute), Delete: schema.DefaultTimeout(3 * time.Minute), }, diff --git a/internal/service/ec2/vpc_network_interface_sg_attachment_test.go b/internal/service/ec2/vpc_network_interface_sg_attachment_test.go index 6cc5817f346..230290eb50f 100644 --- a/internal/service/ec2/vpc_network_interface_sg_attachment_test.go +++ b/internal/service/ec2/vpc_network_interface_sg_attachment_test.go @@ -18,7 +18,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) -func TestAccVPCNetworkInterfaceSgAttachment_basic(t *testing.T) { +func TestAccVPCNetworkInterfaceSGAttachment_basic(t *testing.T) { ctx := acctest.Context(t) networkInterfaceResourceName := "aws_network_interface.test" securityGroupResourceName := "aws_security_group.test" @@ -49,7 +49,7 @@ func TestAccVPCNetworkInterfaceSgAttachment_basic(t *testing.T) { }) } -func TestAccVPCNetworkInterfaceSgAttachment_disappears(t *testing.T) { +func TestAccVPCNetworkInterfaceSGAttachment_disappears(t *testing.T) { ctx := acctest.Context(t) resourceName := "aws_network_interface_sg_attachment.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -72,7 +72,7 @@ func TestAccVPCNetworkInterfaceSgAttachment_disappears(t *testing.T) { }) } -func TestAccVPCNetworkInterfaceSgAttachment_instance(t *testing.T) { +func TestAccVPCNetworkInterfaceSGAttachment_instance(t *testing.T) { ctx := acctest.Context(t) instanceResourceName := "aws_instance.test" securityGroupResourceName := "aws_security_group.test" @@ -97,7 +97,7 @@ func TestAccVPCNetworkInterfaceSgAttachment_instance(t *testing.T) { }) } -func TestAccVPCNetworkInterfaceSgAttachment_multiple(t *testing.T) { +func TestAccVPCNetworkInterfaceSGAttachment_multiple(t *testing.T) { ctx := acctest.Context(t) networkInterfaceResourceName := "aws_network_interface.test" securityGroupResourceName1 := "aws_security_group.test.0" diff --git a/website/docs/r/network_interface_sg_attachment.html.markdown b/website/docs/r/network_interface_sg_attachment.html.markdown index a2e5a85a4bc..b40027195d1 100644 --- a/website/docs/r/network_interface_sg_attachment.html.markdown +++ b/website/docs/r/network_interface_sg_attachment.html.markdown @@ -99,7 +99,6 @@ This resource exports no additional attributes. - `create` - (Default `3m`) - `read` - (Default `3m`) -- `update` - (Default `3m`) - `delete` - (Default `3m`) ## Import