terraform.aws-baseline-infra/modules/util/awscli
2023-07-03 20:02:11 +08:00
..
main.tf UPD: changed to bash, added pipeline option, and switched to jq @base64 2023-07-03 19:57:25 +08:00
README.md UPD: added reference to upstream module 2023-07-03 20:02:11 +08:00
run_awscli.sh UPD: changed to bash, added pipeline option, and switched to jq @base64 2023-07-03 19:57:25 +08:00
variables.tf UPD: changed to bash, added pipeline option, and switched to jq @base64 2023-07-03 19:57:25 +08:00

awscli module

This module executes awscli and returns the output.

input variables

Set the temp credentials if role switching is needed. Otherwise, leave them alone.

variable type required description
access_key string no for role switching
secret_key string no for role switching
session_token string no for role switching
aws_cli_commands string yes command and parameters after aws

output variable

Normally terraform only produces a simple map of string in output. To work around this, awscli outout are base64 encoded. The output variable is then base64decoded back to the original text.

variable type description
awscli_output string output from awscli

Usage example

module "awscli_exec" {
  source = "../../modules/util/awscli"

  access_key       = module.as_role.temp_credential.AccessKeyId
  secret_key       = module.as_role.temp_credential.SecretAccessKey
  session_token    = module.as_role.temp_credential.SessionToken
  aws_cli_commands = "ec2 describe-instances --query Reservations[].Instances[].InstanceId"
}

output awscli_output {
  value = module.awscli_exec.awscliout
}

Output

Outputs:

awscli_output = [
  "i-0cd5e682bc68dbcd2",
  "i-050d4adeafaa53cd0",
  "i-008328e9dfb56b883",
  "i-0634c5ef3528a7b6f",
  "i-0dc9009c249f3e3bd",
  "i-08034d509751ff058",
  "i-0bdd375df2b78a620",
  "i-0655d2b3716b1383e",
]

References

This module is based on https://registry.terraform.io/modules/digitickets/cli/aws/latest