forked from telia-oss/terraform-aws-iam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
97 lines (80 loc) · 2.2 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
terraform {
required_version = "~> 0.14"
backend "s3" {
key = "terraform-modules/development/terraform-module-template/default.tfstate"
bucket = "<test-account-id>-terraform-state"
dynamodb_table = "<test-account-id>-terraform-state"
acl = "bucket-owner-full-control"
encrypt = "true"
kms_key_id = "<kms-key-id>"
region = "eu-west-1"
}
}
provider "aws" {
#version = "3.27.0" This is moved into required_providers block on terraform 0.14
region = "eu-west-1"
allowed_account_ids = ["<test-account-id>"]
}
data "aws_caller_identity" "current" {}
module "admin" {
source = "../../modules/user"
name = "first.last.admin"
path = "/admins/"
keybase = "rickardlofstrom"
}
module "user_policy" {
source = "../../modules/user-policies"
}
module "developer" {
source = "../../modules/user"
name = "first.last.developer"
path = "/developer/"
keybase = "rickardlofstrom"
}
module "user_roles" {
source = "../../modules/user-roles"
trusted_account = data.aws_caller_identity.current.account_id
view_only_role_suffix = "read-only"
admin_role_suffix = "administrator"
admin_users = [
"admins/first.last.admin",
]
view_only_users = [
"developer/first.last.developer",
]
}
module "machine_role" {
source = "../../modules/machine-role"
name = "machine-user-role"
trusted_principals = [
aws_iam_role.example_lambda_role.arn,
]
}
resource "aws_iam_role" "example_lambda_role" {
name = "example_lambda_role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "basic-exec" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
role = aws_iam_role.example_lambda_role.name
}
resource "aws_lambda_function" "example" {
function_name = "example-lambda-function"
handler = "lambda.handler"
role = aws_iam_role.example_lambda_role.arn
runtime = "nodejs14.x"
filename = "lambda.zip"
}