-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathmain.tf
34 lines (28 loc) · 838 Bytes
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Configure the AWS provider
provider "aws" {
region = "eu-west-1"
}
# Create an IAM user
resource "aws_iam_user" "example" {
count = "${length(var.user_names)}"
name = "${element(var.user_names, count.index)}"
}
# Data source: IAM policy document
data "aws_iam_policy_document" "ec2_read_only" {
statement {
effect = "Allow"
actions = ["ec2:Describe*"]
resources = ["*"]
}
}
# Create an IAM policy
resource "aws_iam_policy" "ec2_read_only" {
name = "ec2-read-only"
policy = "${data.aws_iam_policy_document.ec2_read_only.json}"
}
# Create an IAM user policy attachement
resource "aws_iam_user_policy_attachment" "ec2_access" {
count = "${length(var.user_names)}"
user = "${element(aws_iam_user.example.*.name, count.index)}"
policy_arn = "${aws_iam_policy.ec2_read_only.arn}"
}