-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
105 lines (82 loc) · 2.66 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
98
99
100
101
102
103
104
105
# AWS IAM role used by Humanitec to provision resources
locals {
admin_policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess"
humanitec_user_arn = "arn:aws:iam::767398028804:user/humanitec"
}
resource "random_password" "external_id" {
length = 16
special = false
}
data "aws_iam_policy_document" "instance_assume_role_policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "AWS"
identifiers = [local.humanitec_user_arn]
}
condition {
test = "StringEquals"
variable = "sts:ExternalId"
values = [random_password.external_id.result]
}
}
}
resource "aws_iam_role" "humanitec_provisioner" {
name = var.name
assume_role_policy = data.aws_iam_policy_document.instance_assume_role_policy.json
}
resource "aws_iam_role_policy_attachment" "humanitec_provisioner" {
role = aws_iam_role.humanitec_provisioner.name
policy_arn = local.admin_policy_arn
}
resource "humanitec_resource_account" "humanitec_provisioner" {
id = var.name
name = var.name
type = "aws-role"
credentials = jsonencode({
aws_role = aws_iam_role.humanitec_provisioner.arn
external_id = random_password.external_id.result
})
depends_on = [
# Otherwise the account looses permissions before the resources are deleted
aws_iam_role_policy_attachment.humanitec_provisioner
]
}
# Example application and resource definition criteria
resource "humanitec_application" "app" {
id = var.name
name = var.name
}
module "mysql" {
source = "../../../humanitec-resource-defs/mysql/basic"
resource_packs_aws_url = var.resource_packs_aws_url
resource_packs_aws_rev = var.resource_packs_aws_rev
append_logs_to_error = true
driver_account = humanitec_resource_account.humanitec_provisioner.id
region = var.region
prefix = var.prefix
name = var.name
database_name = "my_database"
username = "username"
password = "password"
create_db_subnet_group = true
subnet_ids = var.subnet_ids
vpc_security_group_ids = [aws_security_group.mysql.id]
}
resource "humanitec_resource_definition_criteria" "mysql" {
resource_definition_id = module.mysql.id
app_id = humanitec_application.app.id
force_delete = true
}
resource "aws_security_group" "mysql" {
name = "mysql"
description = "mysql"
vpc_id = var.vpc_id
}
resource "aws_vpc_security_group_ingress_rule" "k8s_node_mysql" {
security_group_id = aws_security_group.mysql.id
referenced_security_group_id = var.k8s_node_security_group_id
from_port = 3306
ip_protocol = "tcp"
to_port = 3306
}