-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
70 additions
and
45 deletions.
There are no files selected for viewing
24 changes: 0 additions & 24 deletions
24
...raform/05-tips-and-tricks/loops-and-if-statements/live/global/multiple-s3-buckets/main.tf
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
...d-tricks/loops-and-if-statements/live/global/three-iam-users-for-each/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# IAM user for_each example | ||
|
||
This folder contains example [Terraform](https://www.terraform.io/) configuration that create several | ||
[IAM](https://aws.amazon.com/iam/) users in an [Amazon Web Services (AWS) account](http://aws.amazon.com/). | ||
|
||
For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, Deployment, and Gotchas", of | ||
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*. | ||
|
||
## Pre-requisites | ||
|
||
* You must have [Terraform](https://www.terraform.io/) installed on your computer. | ||
* You must have an [Amazon Web Services (AWS) account](http://aws.amazon.com/). | ||
|
||
Please note that this code was written for Terraform 0.12.x. | ||
|
||
## Quick start | ||
|
||
**Please note that this example will deploy real resources into your AWS account. We have made every effort to ensure | ||
all the resources qualify for the [AWS Free Tier](https://aws.amazon.com/free/), but we are not responsible for any | ||
charges you may incur.** | ||
|
||
Configure your [AWS access | ||
keys](http://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys) as | ||
environment variables: | ||
|
||
``` | ||
export AWS_ACCESS_KEY_ID=(your access key id) | ||
export AWS_SECRET_ACCESS_KEY=(your secret access key) | ||
``` | ||
|
||
Deploy the code: | ||
|
||
``` | ||
terraform init | ||
terraform apply | ||
``` | ||
|
||
Clean up when you're done: | ||
|
||
``` | ||
terraform destroy | ||
``` |
16 changes: 16 additions & 0 deletions
16
...m/05-tips-and-tricks/loops-and-if-statements/live/global/three-iam-users-for-each/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
terraform { | ||
required_version = ">= 0.12, < 0.13" | ||
} | ||
|
||
provider "aws" { | ||
region = "us-east-2" | ||
|
||
# Allow any 2.x version of the AWS provider | ||
version = "~> 2.0" | ||
} | ||
|
||
resource "aws_iam_user" "example" { | ||
for_each = toset(var.user_names) | ||
name = each.value | ||
} | ||
|
7 changes: 7 additions & 0 deletions
7
...5-tips-and-tricks/loops-and-if-statements/live/global/three-iam-users-for-each/outputs.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
output "all_arns" { | ||
value = values(aws_iam_user.example)[*].arn | ||
} | ||
|
||
output "all_users" { | ||
value = aws_iam_user.example | ||
} |
5 changes: 5 additions & 0 deletions
5
...tips-and-tricks/loops-and-if-statements/live/global/three-iam-users-for-each/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
variable "user_names" { | ||
description = "Create IAM users with these names" | ||
type = list(string) | ||
default = ["neo", "trinity", "morpheus"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters