2023-07-01 16:52:19 +08:00
|
|
|
# awscli module
|
2023-07-03 08:24:24 +08:00
|
|
|
This module executes awscli and returns the output.
|
2023-07-01 16:52:19 +08:00
|
|
|
|
2023-07-03 08:24:24 +08:00
|
|
|
# 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
|
2023-07-01 16:52:19 +08:00
|
|
|
```hcl
|
|
|
|
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
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2023-07-03 08:24:24 +08:00
|
|
|
Output
|
2023-07-01 16:52:19 +08:00
|
|
|
```
|
|
|
|
Outputs:
|
|
|
|
|
|
|
|
awscli_output = [
|
|
|
|
"i-0cd5e682bc68dbcd2",
|
|
|
|
"i-050d4adeafaa53cd0",
|
|
|
|
"i-008328e9dfb56b883",
|
|
|
|
"i-0634c5ef3528a7b6f",
|
|
|
|
"i-0dc9009c249f3e3bd",
|
|
|
|
"i-08034d509751ff058",
|
|
|
|
"i-0bdd375df2b78a620",
|
|
|
|
"i-0655d2b3716b1383e",
|
|
|
|
]
|
2023-07-03 20:02:11 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
# References
|
|
|
|
This module is based on https://registry.terraform.io/modules/digitickets/cli/aws/latest
|