Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vpc/eni_sg_attach: Add configurable timeouts #35435

Merged
merged 4 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/35435.txt
Original file line number Diff line number Diff line change
@@ -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
```
18 changes: 17 additions & 1 deletion internal/service/ec2/vpc_network_interface_sg_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"log"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
Expand All @@ -25,10 +26,17 @@ 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),
Delete: schema.DefaultTimeout(3 * time.Minute),
},

Schema: map[string]*schema.Schema{
"network_interface_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -99,7 +107,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())

Expand All @@ -121,6 +129,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ 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`)
- `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:
Expand Down
Loading