Skip to content

Commit

Permalink
setup directory
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Mar 22, 2023
1 parent 09f0d3e commit 67d956d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 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 @@ -175,6 +175,7 @@ No modules.
| [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 |
| [null_resource.setup_directory](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
16 changes: 11 additions & 5 deletions tag-shared-vpc-resources/tag-network-acls.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,25 @@ data "aws_network_acls" "network_acls" {
# there is still no aws_network_acl, but there is an issue for it
# https://github.com/hashicorp/terraform-provider-aws/issues/19754

resource "null_resource" "setup_directory" {
triggers = {
directory = "setup"
}

provisioner "local-exec" {
command = "test -d ${path.root}/${self.triggers.directory} || mkdir -p ${path.root}/${self.triggers.directory}"
}
}

resource "null_resource" "network_acl" {
for_each = toset(flatten(concat([for k, v in data.aws_network_acls.network_acls : v.ids])))
triggers = {
directory = "setup"
directory = null_resource.setup_directory.triggers.directory
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" {
command = "test -d ${path.root}/${self.triggers.directory} || mkdir -p ${path.root}/${self.triggers.directory}"
}

provisioner "local-exec" {
working_dir = path.root
command = "${path.module}/bin/assume_role_wrapper.sh aws ec2 describe-network-acls --network-acl-id ${each.key} --output json > ${self.triggers.directory}/${self.triggers.filename}"
Expand Down

0 comments on commit 67d956d

Please sign in to comment.