-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.tf
82 lines (68 loc) · 1.82 KB
/
example.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
resource "aws_iam_role" "mysqlbatch" {
name = "mysqlbatch_lambda"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = "lambda.amazonaws.com"
}
}
]
})
}
resource "aws_iam_role_policy_attachment" "mysqlbatch" {
role = aws_iam_role.mysqlbatch.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
}
resource "aws_iam_role_policy_attachment" "mysqlbatch_ssm" {
role = aws_iam_role.mysqlbatch.name
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMReadOnlyAccess"
}
data "archive_file" "mysqlbatch_dummy" {
type = "zip"
output_path = "${path.module}/mysqlbatch_dummy.zip"
source {
content = "mysqlbatch_dummy"
filename = "bootstrap"
}
depends_on = [
null_resource.mysqlbatch_dummy
]
}
resource "null_resource" "mysqlbatch_dummy" {}
resource "aws_lambda_function" "mysqlbatch" {
lifecycle {
ignore_changes = all
}
function_name = "mysqlbatch"
role = aws_iam_role.mysqlbatch.arn
handler = "bootstrap"
runtime = "provided.al2"
vpc_config {
subnet_ids = data.aws_subnets.default.ids
security_group_ids = [data.aws_security_group.internal.id]
}
filename = data.archive_file.mysqlbatch_dummy.output_path
}
resource "aws_ssm_parameter" "DBPASSWORD" {
name = "/mysqlbatch/DBPASSWORD"
description = "mysqlbatch db password"
type = "SecureString"
value = local.db_password
}
data "aws_subnets" "default" {
filter {
name = "vpc-id"
values = [local.vpc_id]
}
}
data "aws_security_group" "internal" {
id = local.security_group_id
}
data "aws_rds_cluster" "mysql" {
cluster_identifier = local.cluster_identifier
}