-
Notifications
You must be signed in to change notification settings - Fork 132
/
instance_profile.tf
90 lines (80 loc) · 2.42 KB
/
instance_profile.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
// create a data s3 bucket for demo purposes
resource "aws_s3_bucket" "data_bucket" {
bucket = "data-bucket-for-test" // hard-coded value for demo only
acl = "private"
force_destroy = true
}
resource "aws_iam_policy" "added_policy" {
name = "grant-specific-s3-policy"
description = "A test policy"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "grantS3Access",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:GetObjectVersion",
"s3:PutObject",
"s3:DeleteObject",
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource": [
"arn:aws:s3:::data-bucket-for-test/*",
"arn:aws:s3:::data-bucket-for-test"
]
}
]
}
EOF
}
data "aws_iam_policy_document" "assume_role_for_ec2" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
identifiers = ["ec2.amazonaws.com"]
type = "Service"
}
}
}
data "aws_iam_policy_document" "pass_role_for_s3_access" {
statement {
effect = "Allow"
actions = ["iam:PassRole"]
resources = [aws_iam_role.role_for_s3_access.arn]
}
}
resource "aws_iam_role" "role_for_s3_access" {
name = "${local.prefix}-ec2-role-for-s3"
description = "iam role for ec2 to access s3"
assume_role_policy = data.aws_iam_policy_document.assume_role_for_ec2.json
tags = var.tags
}
resource "aws_iam_policy" "pass_role_for_s3_access" {
name = "${local.prefix}-pass-role-for-s3-access"
path = "/"
policy = data.aws_iam_policy_document.pass_role_for_s3_access.json
}
resource "aws_iam_role_policy_attachment" "cross_account" {
policy_arn = aws_iam_policy.pass_role_for_s3_access.arn
role = aws_iam_role.role_for_s3_access.name
}
// add grant s3 access policy to role
resource "aws_iam_role_policy_attachment" "s3-policy-attach" {
policy_arn = aws_iam_policy.added_policy.arn
role = aws_iam_role.role_for_s3_access.name
}
resource "aws_iam_instance_profile" "instance_profile" {
name = "${local.prefix}-instance-profile"
role = aws_iam_role.role_for_s3_access.name
}
/*
resource "databricks_instance_profile" "instance_profile" {
instance_profile_arn = aws_iam_instance_profile.instance_profile.arn
skip_validation = true
}
*/