Skip to content

Commit

Permalink
Correctly extract security group name for tags (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuru authored Oct 22, 2021
1 parent 3638d38 commit c6e4156
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ module "new_security_group" {
security_group_create_timeout = "5m"
security_group_delete_timeout = "2m"

security_group_name = [format("%s-%s", module.this.id, "new")]

context = module.this.context
}

Expand All @@ -135,7 +137,8 @@ module "target_security_group" {
target_security_group_id = [aws_security_group.target.id]
rules = var.rules

vpc_id = module.vpc.vpc_id
security_group_name = [aws_security_group.target.name_prefix]
vpc_id = module.vpc.vpc_id

context = module.this.context
}
Expand Down
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ resource "aws_security_group" "default" {

description = var.security_group_description
vpc_id = var.vpc_id
tags = merge(module.this.tags, try(length(var.security_group_name), 0) > 0 ? { Name = var.security_group_name } : {})
tags = merge(module.this.tags, try(length(var.security_group_name[0]), 0) > 0 ? { Name = var.security_group_name[0] } : {})

revoke_rules_on_delete = var.revoke_rules_on_delete

Expand Down Expand Up @@ -93,7 +93,7 @@ resource "aws_security_group" "cbd" {

description = var.security_group_description
vpc_id = var.vpc_id
tags = merge(module.this.tags, try(length(var.security_group_name), 0) > 0 ? { Name = var.security_group_name } : {})
tags = merge(module.this.tags, try(length(var.security_group_name[0]), 0) > 0 ? { Name = var.security_group_name[0] } : {})

revoke_rules_on_delete = var.revoke_rules_on_delete

Expand Down Expand Up @@ -148,7 +148,7 @@ resource "aws_security_group_rule" "keyed" {
description = each.value.description
cidr_blocks = length(each.value.cidr_blocks) == 0 ? null : each.value.cidr_blocks
ipv6_cidr_blocks = length(each.value.ipv6_cidr_blocks) == 0 ? null : each.value.ipv6_cidr_blocks
prefix_list_ids = length(each.value.prefix_list_ids) == 0 ? null : each.value.prefix_list_ids
prefix_list_ids = length(each.value.prefix_list_ids) == 0 ? [] : each.value.prefix_list_ids
self = each.value.self

security_group_id = local.security_group_id
Expand Down
2 changes: 1 addition & 1 deletion test/src/examples_complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestExamplesComplete(t *testing.T) {

assert.Contains(t, newSgID, "sg-", "SG ID should contains substring 'sg-'")
assert.Contains(t, newSgARN, "arn:aws:ec2", "SG ID should contains substring 'arn:aws:ec2'")
assert.Equal(t, "eg-ue2-test-sg-"+randID, newSgName)
assert.Equal(t, "eg-ue2-test-sg-"+randID+"-new", newSgName)

// Verify that outputs are valid when an existing security group is provided
targetSgID := terraform.Output(t, terraformOptions, "target_sg_id")
Expand Down

0 comments on commit c6e4156

Please sign in to comment.