Skip to content

Commit 98f8b1c

Browse files
authored
Merge pull request Coalfire-CF#19 from Coalfire-CF/fix_sg_attachment
Fix_sg_attachment
2 parents 987adad + b6522d2 commit 98f8b1c

File tree

5 files changed

+4
-15
lines changed

5 files changed

+4
-15
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@
22
# Each line is a file pattern followed by one or more owners.
33

44
# These owners will be the default owners for everything in
5-
# the repo. Unless a later match takes precedence,
6-
# @douglas-f and @i-ate-a-vm will be requested for
7-
# review when someone opens a pull request.
8-
* @cstano @i-ate-a-vm
5+
# the repo.
6+
* @az-kennedy @herman-wong-cf

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ module "ad2" {
189189
| [aws_lb_target_group_attachment.target_group_attachment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_target_group_attachment) | resource |
190190
| [aws_network_interface_attachment.eni_attachment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/network_interface_attachment) | resource |
191191
| [aws_network_interface_sg_attachment.additional](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/network_interface_sg_attachment) | resource |
192-
| [aws_network_interface_sg_attachment.primary](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/network_interface_sg_attachment) | resource |
193192
| [aws_volume_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/volume_attachment) | resource |
194193
| [aws_iam_policy.AmazonSSMManagedInstanceCore](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy) | data source |
195194

@@ -240,6 +239,7 @@ module "ad2" {
240239
| <a name="output_iam_role_arn"></a> [iam\_role\_arn](#output\_iam\_role\_arn) | The AWS IAM Role arn created |
241240
| <a name="output_iam_role_name"></a> [iam\_role\_name](#output\_iam\_role\_name) | The AWS IAM Role arn created |
242241
| <a name="output_instance_id"></a> [instance\_id](#output\_instance\_id) | The AWS Instance id created |
242+
| <a name="output_network_interface_id"></a> [network\_interface\_id](#output\_network\_interface\_id) | The network interface ID for the AWS instance |
243243
| <a name="output_primary_private_ip_addresses"></a> [primary\_private\_ip\_addresses](#output\_primary\_private\_ip\_addresses) | A list of the primary private IP addesses assigned to the ec2 instance |
244244
| <a name="output_sg_id"></a> [sg\_id](#output\_sg\_id) | The id of the security group created |
245245
| <a name="output_tags"></a> [tags](#output\_tags) | List of tags of instances |

ec2.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ resource "aws_instance" "this" {
2121
private_ip = var.private_ip
2222
associate_public_ip_address = var.associate_public_ip || var.associate_eip
2323
source_dest_check = var.source_dest_check
24-
vpc_security_group_ids = [module.security_group.id]
24+
vpc_security_group_ids = length(var.additional_security_groups) > 0 ? concat([module.security_group.id], var.additional_security_groups) : [module.security_group.id]
2525

2626
### STORAGE ###
2727
root_block_device {

locals.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ locals {
1010

1111
# For additional sg attachment
1212
locals {
13-
additional_sg_to_primary_eni = setproduct(var.additional_security_groups, aws_instance.this[*].primary_network_interface_id)
1413
additional_sg_to_additional_eni = setproduct(var.additional_security_groups, var.additional_eni_ids)
1514
}
1615

sg.tf

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ module "security_group" {
1111
network_interface_resource_associations = var.additional_eni_ids
1212
}
1313

14-
# Attach additional security groups to all instance primary network interfaces
15-
resource "aws_network_interface_sg_attachment" "primary" {
16-
count = length(local.additional_sg_to_primary_eni)
17-
18-
security_group_id = local.additional_sg_to_primary_eni[count.index][0]
19-
network_interface_id = local.additional_sg_to_primary_eni[count.index][1]
20-
}
21-
2214
# Attach additional security groups to any additional network interfaces
2315
resource "aws_network_interface_sg_attachment" "additional" {
2416
count = length(local.additional_sg_to_additional_eni)

0 commit comments

Comments
 (0)