Skip to content

Commit

Permalink
make network-acls work
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Oct 7, 2022
1 parent 292bec6 commit d0644b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions tag-shared-vpc-resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ No modules.
| [aws_ec2_tag.transit_gateway](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_tag) | resource |
| [aws_ec2_tag.vpcs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_tag) | resource |
| [null_resource.network_acl](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [null_resource.network_acls](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [aws_arn.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source |
| [aws_arn.network_account](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source |
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
Expand Down
23 changes: 19 additions & 4 deletions tag-shared-vpc-resources/tag-network-acls.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ resource "null_resource" "network_acl" {
directory = "setup"
network_acl_id = each.key
filename = "network_acl.${each.key}.json"
full_filename = format("%v/%v/%v", path.root, "setup", "network_acl.${each.key}.json")
}

provisioner "local-exec" {
Expand All @@ -44,9 +45,21 @@ resource "null_resource" "network_acl" {
data "local_file" "network_acl" {
# for_each = toset(flatten(concat([for k, v in data.aws_network_acls.network_acls : v.ids])))
for_each = null_resource.network_acl
filename = format("%v/%v/%v", path.root, each.value.triggers.directory, each.value.triggers.filename)
# filename = format("%v/%v/%v", path.root, each.value.triggers.directory, each.value.triggers.filename)
filename = each.value.triggers.full_filename
}

resource "null_resource" "network_acls" {
triggers = {
network_acls = join(",", [for k, v in data.local_file.network_acl : v.filename])
filename = format("%v/%v/%v", path.root, "setup", "network_acls_extracted.dat")
}
provisioner "local-exec" {
command = "touch ${self.triggers.filename}"
}
}


## output "network_acls" {
## value = data.aws_network_acls.network_acls
## }
Expand All @@ -59,9 +72,9 @@ data "local_file" "network_acl" {
locals {
_nacl_enabled = var.tag_enabled_network_acls
_network_acls = local._nacl_enabled ? { for k, v in data.local_file.network_acl : k => jsondecode(v.content) } : {}
network_acls = { for k, v in local._network_acls : k => lookup(v, "NetworkAcls", [{ "Tags" : [], "OwnerId" : "" }])[0] }
network_acls_tags = { for k, v in local.network_acls : k => merge({ for t in v.Tags : t.Key => t.Value }, { "boc:vpc:owner_id" = v.OwnerId }) }
network_acls_tags_map = flatten([for k, v in local.network_acls_tags : [for tk, tv in v : { label = format("%v__%v", k, tk), network_acl_id = k, key = tk, value = tv }]])
network_acls = fileexists(null_resource.network_acls.triggers.filename) ? { for k, v in local._network_acls : k => lookup(v, "NetworkAcls", [{ "Tags" : [], "OwnerId" : "" }])[0] } : {}
network_acls_tags = fileexists(null_resource.network_acls.triggers.filename) ? { for k, v in local.network_acls : k => merge({ for t in v.Tags : t.Key => t.Value }, { "boc:vpc:owner_id" = v.OwnerId }) } : {}
network_acls_tags_map = fileexists(null_resource.network_acls.triggers.filename) ? flatten([for k, v in local.network_acls_tags : [for tk, tv in v : { label = format("%v__%v", k, tk), network_acl_id = k, key = tk, value = tv }]]) : []
}

resource "aws_ec2_tag" "network_acls" {
Expand All @@ -70,4 +83,6 @@ resource "aws_ec2_tag" "network_acls" {
resource_id = each.value.network_acl_id
key = each.value.key
value = each.value.value

# depends_on = [null_resource.network_acl]
}

0 comments on commit d0644b9

Please sign in to comment.