UPD: updated shell script output and readme file

This commit is contained in:
xpk 2023-07-03 08:24:24 +08:00
parent a67ac7b052
commit f061b0dc8d
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
2 changed files with 26 additions and 6 deletions

View File

@ -1,8 +1,26 @@
# awscli module
This module executes awscli. Json output goes through base64 encode and decode to work around
terraform map of string requirements for external data.
This module executes awscli and returns the output.
## Example root module
# 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
```hcl
module "awscli_exec" {
source = "../../modules/util/awscli"
@ -18,7 +36,7 @@ output awscli_output {
}
```
Sample output
Output
```
Outputs:

View File

@ -36,5 +36,7 @@ export AWS_RETRY_MODE=standard
export AWS_MAX_ATTEMPTS=3
# Run the AWS_CLI command
aws sts get-caller-identity --query Arn > /tmp/awscli.log
echo '{"awscliout" : "'$(aws ${AWS_CLI_COMMANDS} | base64 -w0)'"}' | tee -a /tmp/awscli.log
# aws sts get-caller-identity --query Arn > /tmp/awscli.log
# echo '{"awscliout" : "'$(aws ${AWS_CLI_COMMANDS} | base64 -w0)'"}' | tee -a /tmp/awscli.log
jq -n --arg jqarg1 $(aws ${AWS_CLI_COMMANDS} | base64 -w0) '{ "awscliout" : $jqarg1 }'