Skip to content

Instantly share code, notes, and snippets.

@romicofre
Last active July 2, 2023 21:10
Show Gist options
  • Save romicofre/6c815c39891c744a6790e86459948a98 to your computer and use it in GitHub Desktop.
Save romicofre/6c815c39891c744a6790e86459948a98 to your computer and use it in GitHub Desktop.
AWS - Create a list users with Terraform resource
# Variables
variable "region"{
type = string
}
variable "email_list"{
type = list(string)
}
# Sample tfvars or default values
# region = "us-east-1"
# email_list = [
# "varvarie@vvv.Bo",
# "conte@mal.yup"
# ]
provider "aws" {
region = var.region
}
resource "aws_iam_user" "user_mail" {
for_each = toset(var.email_list)
name = each.key
path = "/"
force_destroy = true
}
resource "aws_iam_user_login_profile" "login_user_mail" {
for_each = aws_iam_user.user_mail
user = each.key
depends_on = [aws_iam_user.user_mail]
password_reset_required = true
}
//output "password" { # TODO : print passwords?
// value = aws_iam_user_login_profile.login_user_mail
// depends_on = [aws_iam_user_login_profile.login_user_mail]
//}
# Get password by email
//terraform state show 'aws_iam_user_login_profile.login_user_mail["email_in_list@hello.poc"]' | grep "password"
# Add role to user:
# https://github.com/romicofre/terraform_exercises/blob/main/aws_examples/iam/users_by_list/main.tf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment