Skip to content

Commit

Permalink
Fix for when this module is used in an iterative environment
Browse files Browse the repository at this point in the history
In the use case documented in the README.md, if there are multiple ASGs,
and this module is then called iteratively, each iteration will now
correctly have its own output.

This may also be fixing #3.

In local testing, for a new ASG being added to a pool of existing ASGs,
the recorded output files are showing the correct values, with the string
null being recorded for the new ASG (which is correct in this context).
  • Loading branch information
rquadling committed May 26, 2022
1 parent 1f1b89a commit 417fc66
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ module "current_desired_capacity" {

| Name | Version |
|------|---------|
| <a name="provider_external"></a> [external](#provider\_external) | ~> 2.0 |
| <a name="provider_local"></a> [local](#provider\_local) | ~> 2.0 |
| <a name="provider_external"></a> [external](#provider\_external) | 2.1.0 |
| <a name="provider_local"></a> [local](#provider\_local) | 2.1.0 |

## Modules

Expand Down
24 changes: 22 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
locals {
joined_aws_cli_command = join(" ", var.aws_cli_commands)
output_file = format(
"%s/temp/results-%s.json",
path.module,
md5(
join(
"-",
[
var.assume_role_arn,
var.role_session_name,
local.joined_aws_cli_command,
var.aws_cli_query,
var.debug_log_filename
]
)
)
)
}

data "external" "awscli_program" {
program = [format("%s/scripts/awsWithAssumeRole.sh", path.module)]
query = {
assume_role_arn = var.assume_role_arn
role_session_name = var.role_session_name
aws_cli_commands = join(" ", var.aws_cli_commands)
aws_cli_commands = local.joined_aws_cli_command
aws_cli_query = var.aws_cli_query
output_file = format("%s/temp/results.json", path.module)
output_file = local.output_file
debug_log_filename = var.debug_log_filename
}
}
Expand Down
3 changes: 3 additions & 0 deletions scripts/awsWithAssumeRole.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ fi
# Make sure output file directory exists
mkdir -p "$(dirname ${OUTPUT_FILE})"

# Make sure output file does not exist
rm -f "${OUTPUT_FILE}"

# Disable any assigned pager
export AWS_PAGER=""

Expand Down

0 comments on commit 417fc66

Please sign in to comment.