forked from rancherfederal/rke2-aws-tf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.tf
131 lines (122 loc) · 4.23 KB
/
data.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
module "init" {
source = "./modules/userdata"
server_url = module.cp_lb.dns
token_bucket = module.statestore.bucket
token_object = module.statestore.token_object
config = var.rke2_config
pre_userdata = var.pre_userdata
post_userdata = var.post_userdata
ccm = var.enable_ccm
agent = false
}
data "cloudinit_config" "this" {
gzip = true
base64_encode = true
# Main cloud-init config file
part {
filename = "cloud-config.yaml"
content_type = "text/cloud-config"
content = templatefile("${path.module}/modules/nodepool/files/cloud-config.yaml", {
ssh_authorized_keys = var.ssh_authorized_keys
extra_cloud_config_config = var.extra_cloud_config_config
})
}
dynamic "part" {
for_each = var.download ? [1] : []
content {
filename = "00_download.sh"
content_type = "text/x-shellscript"
content = templatefile("${path.module}/modules/common/download.sh", {
# Must not use `version` here since that is reserved
rke2_version = var.rke2_version
type = "server"
})
}
}
part {
filename = "01_rke2.sh"
content_type = "text/x-shellscript"
content = module.init.templated
}
}
#
# IAM Policies
#
data "aws_iam_policy_document" "aws_required" {
count = var.iam_instance_profile == "" ? 1 : 0
# "Leader election" requires querying the instances autoscaling group/instances
statement {
effect = "Allow"
resources = ["*"]
actions = [
"autoscaling:DescribeAutoScalingGroups",
"autoscaling:DescribeAutoScalingInstances",
]
}
}
# Required IAM Policy for AWS CCM
data "aws_iam_policy_document" "aws_ccm" {
count = var.iam_instance_profile == "" && var.enable_ccm ? 1 : 0
statement {
effect = "Allow"
resources = ["*"]
actions = [
"autoscaling:DescribeAutoScalingGroups",
"autoscaling:DescribeLaunchConfigurations",
"autoscaling:DescribeTags",
"autoscaling:DescribeAutoScalingInstances",
"ec2:DescribeInstances",
"ec2:DescribeRegions",
"ec2:DescribeRouteTables",
"ec2:DescribeSecurityGroups",
"ec2:DescribeSubnets",
"ec2:DescribeVolumes",
"ec2:CreateSecurityGroup",
"ec2:CreateTags",
"ec2:CreateVolume",
"ec2:ModifyInstanceAttribute",
"ec2:ModifyVolume",
"ec2:AttachVolume",
"ec2:AuthorizeSecurityGroupIngress",
"ec2:CreateRoute",
"ec2:DeleteRoute",
"ec2:DeleteSecurityGroup",
"ec2:DeleteVolume",
"ec2:DetachVolume",
"ec2:RevokeSecurityGroupIngress",
"ec2:DescribeVpcs",
"elasticloadbalancing:AddTags",
"elasticloadbalancing:AttachLoadBalancerToSubnets",
"elasticloadbalancing:ApplySecurityGroupsToLoadBalancer",
"elasticloadbalancing:CreateLoadBalancer",
"elasticloadbalancing:CreateLoadBalancerPolicy",
"elasticloadbalancing:CreateLoadBalancerListeners",
"elasticloadbalancing:ConfigureHealthCheck",
"elasticloadbalancing:DeleteLoadBalancer",
"elasticloadbalancing:DeleteLoadBalancerListeners",
"elasticloadbalancing:DescribeLoadBalancers",
"elasticloadbalancing:DescribeLoadBalancerAttributes",
"elasticloadbalancing:DetachLoadBalancerFromSubnets",
"elasticloadbalancing:DeregisterInstancesFromLoadBalancer",
"elasticloadbalancing:ModifyLoadBalancerAttributes",
"elasticloadbalancing:RegisterInstancesWithLoadBalancer",
"elasticloadbalancing:SetLoadBalancerPoliciesForBackendServer",
"elasticloadbalancing:AddTags",
"elasticloadbalancing:CreateListener",
"elasticloadbalancing:CreateTargetGroup",
"elasticloadbalancing:DeleteListener",
"elasticloadbalancing:DeleteTargetGroup",
"elasticloadbalancing:DescribeListeners",
"elasticloadbalancing:DescribeLoadBalancerPolicies",
"elasticloadbalancing:DescribeTargetGroups",
"elasticloadbalancing:DescribeTargetHealth",
"elasticloadbalancing:ModifyListener",
"elasticloadbalancing:ModifyTargetGroup",
"elasticloadbalancing:RegisterTargets",
"elasticloadbalancing:DeregisterTargets",
"elasticloadbalancing:SetLoadBalancerPoliciesOfListener",
"iam:CreateServiceLinkedRole",
"kms:DescribeKey"
]
}
}