Skip to content

Commit

Permalink
Merge pull request #35435 from hashicorp/eni_sg_attach_to
Browse files Browse the repository at this point in the history
vpc/eni_sg_attach: Add configurable timeouts
  • Loading branch information
YakDriver committed Jan 22, 2024
2 parents 78ec53a + cf354c5 commit 2eabc1a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
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
8 changes: 8 additions & 0 deletions website/docs/r/network_interface_sg_attachment.html.markdown
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

0 comments on commit 2eabc1a

Please sign in to comment.