|
1 |
| -# .github |
2 |
| -This repo is used for default community health files, such as CONTRIBUTING and CODE_OF_CONDUCT, for this organization. Default files will be used for any public repository in this organization that does not contain its own of that type. |
| 1 | +# terraform-aws-ip-address-release |
| 2 | + |
| 3 | +Sometimes AWS fails to release an allocated IP address when tearing down the associated resources. This lambda will release/delete all network interfaces that are in `Status: Available` as they are not associated with a current AWS resource but can't be used by a new AWS resource. |
| 4 | + |
| 5 | +An exception is made for ENIs attached to DataSync tasks since DataSync only establishes ENIs at task creation time. |
| 6 | + |
| 7 | +This includes a 24 hour cloudwatch alarm to trigger the lambda regularly in an effort to keep the account clean and make the resources available for another consumer. |
| 8 | + |
| 9 | +<!-- BEGIN_TF_DOCS --> |
| 10 | +## Requirements |
| 11 | + |
| 12 | +| Name | Version | |
| 13 | +| ------------------------------------------------------------------------- | -------- | |
| 14 | +| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.14 | |
| 15 | +| <a name="requirement_archive"></a> [archive](#requirement\_archive) | ~> 2.2 | |
| 16 | +| <a name="requirement_aws"></a> [aws](#requirement\_aws) | > 4.0 | |
| 17 | +| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.1.0 | |
| 18 | + |
| 19 | +## Providers |
| 20 | + |
| 21 | +| Name | Version | |
| 22 | +| ------------------------------------------------------------- | ------- | |
| 23 | +| <a name="provider_archive"></a> [archive](#provider\_archive) | ~> 2.2 | |
| 24 | +| <a name="provider_aws"></a> [aws](#provider\_aws) | > 4.0 | |
| 25 | + |
| 26 | +## Modules |
| 27 | + |
| 28 | +| Name | Source | Version | |
| 29 | +| --------------------------------------------- | ------ | ------- | |
| 30 | +| <a name="module_iam"></a> [iam](#module\_iam) | ./iam | n/a | |
| 31 | + |
| 32 | +## Resources |
| 33 | + |
| 34 | +| Name | Type | |
| 35 | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | |
| 36 | +| [aws_cloudwatch_event_rule.ip_address_release_lambda_interval](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_rule) | resource | |
| 37 | +| [aws_cloudwatch_event_target.ip_address_release_lambda_attach](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_target) | resource | |
| 38 | +| [aws_lambda_function.ip_address_release_lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function) | resource | |
| 39 | +| [aws_lambda_permission.event_permission](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource | |
| 40 | +| [archive_file.lambda_source](https://registry.terraform.io/providers/hashicorp/archive/latest/docs/data-sources/file) | data source | |
| 41 | +| [aws_security_group.https-internet-egress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/security_group) | data source | |
| 42 | +| [aws_vpc.internal](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source | |
| 43 | + |
| 44 | +## Inputs |
| 45 | + |
| 46 | +| Name | Description | Type | Default | Required | |
| 47 | +| ---------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | -------------- | ------- | :------: | |
| 48 | +| <a name="input_account_name"></a> [account\_name](#input\_account\_name) | The account name for use in alarm description. | `string` | n/a | yes | |
| 49 | +| <a name="input_create_iam_role"></a> [create\_iam\_role](#input\_create\_iam\_role) | Pass in `false` if you are supplying an IAM role. | `bool` | `true` | no | |
| 50 | +| <a name="input_iam_role_arn"></a> [iam\_role\_arn](#input\_iam\_role\_arn) | The ARN of the IAM Role to use (creates a new one if set to `null`) | `string` | `null` | no | |
| 51 | +| <a name="input_internet_egress_security_group"></a> [internet\_egress\_security\_group](#input\_internet\_egress\_security\_group) | Name of a security group that allows internet outbound calls to port 443 | `string` | n/a | yes | |
| 52 | +| <a name="input_permissions_boundary_arn"></a> [permissions\_boundary\_arn](#input\_permissions\_boundary\_arn) | The ARN of the policy that is used to set the permissions boundary for the IAM roles. | `string` | `null` | no | |
| 53 | +| <a name="input_subnet_ids"></a> [subnet\_ids](#input\_subnet\_ids) | Subnets that Lambda will be created with in the VPC | `list(string)` | `[]` | no | |
| 54 | +| <a name="input_timeout"></a> [timeout](#input\_timeout) | Timeout value for the lambda | `number` | `300` | no | |
| 55 | +| <a name="input_usecase"></a> [usecase](#input\_usecase) | Usecase name, can be a team or product name. E.g., 'SRE' | `string` | n/a | yes | |
| 56 | +| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | VPC ID to attach the IP Address Release lambda to. Only necessary if there are multiple VPCs in an account. | `string` | `null` | no | |
| 57 | + |
| 58 | +## Outputs |
| 59 | + |
| 60 | +| Name | Description | |
| 61 | +| ---------------------------------------------------------------------------- | ------------------------------------------- | |
| 62 | +| <a name="output_iam_role_arn"></a> [iam\_role\_arn](#output\_iam\_role\_arn) | The IAM Role created, or the one passed in. | |
| 63 | +<!-- END_TF_DOCS --> |
| 64 | + |
| 65 | +# Multi-region deployment |
| 66 | +The IAM role created for the initial region can be reused for the second region by referencing the outputs from the first region. |
| 67 | +```terraform |
| 68 | +* assumes a non-aliased provider is setup elsewhere |
| 69 | +module "ip-address-release-primary" { |
| 70 | + source = "git::https://github.com/StateFarmIns/terraform-aws-ip-address-release?ref=1.0.0" |
| 71 | +
|
| 72 | + providers = { |
| 73 | + aws = aws |
| 74 | + } |
| 75 | +
|
| 76 | + usecase = "SRE" |
| 77 | + account_name = var.account_name |
| 78 | + permissions_boundary_arn = local.permissions_boundary |
| 79 | + internet_egress_security_group_id = data.aws_security_group.https-internet-egress.id |
| 80 | + vpc_id = data.aws_vpc.internal.id |
| 81 | +} |
| 82 | +
|
| 83 | +* assumes an aliased (secondary) provider is setup elsewhere |
| 84 | +module "ip-address-release-secondary" { |
| 85 | + source = "git::https://github.com/StateFarmIns/terraform-aws-ip-address-release?ref=1.0.0" |
| 86 | +
|
| 87 | + providers = { |
| 88 | + aws = aws.secondary |
| 89 | + } |
| 90 | +
|
| 91 | + usecase = "SRE" |
| 92 | + account_name = var.account_name |
| 93 | + permissions_boundary_arn = local.permissions_boundary |
| 94 | + internet_egress_security_group_id = data.aws_security_group.https-internet-egress_secondary.id |
| 95 | + iam_role_arn = module.ip-address-release-primary.iam_role_arn # reference the IAM Role created earlier |
| 96 | + vpc_id = data.aws_vpc.internal_secondary.id |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +# Links |
| 101 | +* [Why can't I detach or delete an elastic network interface that Lambda created?](https://aws.amazon.com/premiumsupport/knowledge-center/lambda-eni-find-delete/) |
| 102 | +* [Requester Managed Network Interfaces](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/requester-managed-eni.html) |
| 103 | +* findassociations script copied from [AWS-support-tools](https://github.com/awslabs/aws-support-tools) |
| 104 | + |
0 commit comments