Skip to content

Commit e30bdf4

Browse files
twarnockMark Beacom
authored andcommitted
included cloudwatch event. changed tf to ce for lambdas (#79)
1 parent 9549f72 commit e30bdf4

File tree

6 files changed

+55
-21
lines changed

6 files changed

+55
-21
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,5 @@ venv.bak/
112112

113113
# terraform builds
114114
.terraform/
115-
terraform.tfstate*
115+
terraform.tfstate*
116+
*.tfvars

step/cloudwatch.tf

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,30 @@
1-
resource "aws_cloudwatch_log_group" "copy-and-split-log-group" {
2-
name = "/aws/lambda/copy-and-split"
3-
retention_in_days = "1"
1+
// resource "aws_cloudwatch_log_group" "cloudendure-rehost-migration-log-group" {
2+
// name = "/aws/lambda/cloudendure-rehost-migration"
3+
// retention_in_days = "1"
4+
// }
5+
6+
resource "aws_cloudwatch_event_rule" "rehost-migration-rule" {
7+
name = "ce-rehost-migration-rule"
8+
description = ""
9+
event_pattern = <<PATTERN
10+
{
11+
"source": [
12+
"aws.ec2"
13+
],
14+
"detail-type": [
15+
"EC2 Instance State-change Notification"
16+
],
17+
"detail": {
18+
"state": [
19+
"running"
20+
]
21+
}
422
}
23+
PATTERN
24+
}
25+
26+
resource "aws_cloudwatch_event_target" "rehost-migration-target" {
27+
rule = "${aws_cloudwatch_event_rule.rehost-migration-rule.id}"
28+
arn = "${aws_sfn_state_machine.rehost_migration.id}"
29+
role_arn = "${aws_iam_role.iam_for_stepfunction.arn}"
30+
}

step/iam.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# step function related iam
22
resource "aws_iam_role" "iam_for_stepfunction" {
3-
name = "tf-iam-for-stepfunction"
3+
name = "ce-iam-for-stepfunction"
44
assume_role_policy = "${data.aws_iam_policy_document.stepfunction_assume_role_policy_document.json}"
55
}
66

@@ -9,7 +9,7 @@ data "aws_iam_policy_document" "stepfunction_assume_role_policy_document" {
99
actions = ["sts:AssumeRole"]
1010

1111
principals {
12-
type = "Service"
12+
type = "Service"
1313
identifiers = ["states.${var.region}.amazonaws.com"]
1414
}
1515
}
@@ -28,12 +28,12 @@ data "aws_iam_policy_document" "lambda-invoke" {
2828
statement {
2929
effect = "Allow"
3030
actions = [ "sts:AssumeRole" ]
31-
resources = [ "role/arn" ]
31+
resources = [for role in var.assume_role_list: role]
3232
}
3333
}
3434

3535
resource "aws_iam_policy" "lambda-invoke" {
36-
name = "tf-lambda-invoke"
36+
name = "ce-lambda-invoke"
3737
policy = "${data.aws_iam_policy_document.lambda-invoke.json}"
3838
}
3939

@@ -44,7 +44,7 @@ resource "aws_iam_role_policy_attachment" "lambda-invoke" {
4444

4545
# lambda related
4646
resource "aws_iam_role" "iam_for_lambda" {
47-
name = "tf-iam-for-lambda"
47+
name = "ce-iam-for-lambda"
4848
assume_role_policy = "${data.aws_iam_policy_document.iam_for_lambda_assume_role.json}"
4949
}
5050

@@ -67,3 +67,4 @@ resource "aws_iam_role_policy_attachment" "role_policy_lambda_ec2" {
6767
role = "${aws_iam_role.iam_for_lambda.name}"
6868
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2FullAccess"
6969
}
70+

step/lambdas.tf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ data "archive_file" "lambdas" {
77

88
resource "aws_lambda_function" "lambda_find_instance" {
99
filename = "lambdas.zip"
10-
function_name = "tf-find-instance"
10+
function_name = "ce-find-instance"
1111
role = "${aws_iam_role.iam_for_lambda.arn}"
1212
handler = "find_instance.lambda_handler"
1313
source_code_hash = "${data.archive_file.lambdas.output_base64sha256}"
@@ -17,7 +17,7 @@ resource "aws_lambda_function" "lambda_find_instance" {
1717

1818
resource "aws_lambda_function" "lambda_get_instance_status" {
1919
filename = "lambdas.zip"
20-
function_name = "tf-get-instance-status"
20+
function_name = "ce-get-instance-status"
2121
role = "${aws_iam_role.iam_for_lambda.arn}"
2222
handler = "get_instance_status.lambda_handler"
2323
source_code_hash = "${data.archive_file.lambdas.output_base64sha256}"
@@ -27,7 +27,7 @@ resource "aws_lambda_function" "lambda_get_instance_status" {
2727

2828
resource "aws_lambda_function" "lambda_create_image" {
2929
filename = "lambdas.zip"
30-
function_name = "tf-create-image"
30+
function_name = "ce-create-image"
3131
role = "${aws_iam_role.iam_for_lambda.arn}"
3232
handler = "create_image.lambda_handler"
3333
source_code_hash = "${data.archive_file.lambdas.output_base64sha256}"
@@ -37,7 +37,7 @@ resource "aws_lambda_function" "lambda_create_image" {
3737

3838
resource "aws_lambda_function" "lambda_get_image_status" {
3939
filename = "lambdas.zip"
40-
function_name = "tf-get-image-status"
40+
function_name = "ce-get-image-status"
4141
role = "${aws_iam_role.iam_for_lambda.arn}"
4242
handler = "get_image_status.lambda_handler"
4343
source_code_hash = "${data.archive_file.lambdas.output_base64sha256}"
@@ -47,7 +47,7 @@ resource "aws_lambda_function" "lambda_get_image_status" {
4747

4848
resource "aws_lambda_function" "lambda_share_image" {
4949
filename = "lambdas.zip"
50-
function_name = "tf-share-image"
50+
function_name = "ce-share-image"
5151
role = "${aws_iam_role.iam_for_lambda.arn}"
5252
handler = "share_image.lambda_handler"
5353
source_code_hash = "${data.archive_file.lambdas.output_base64sha256}"
@@ -57,7 +57,7 @@ resource "aws_lambda_function" "lambda_share_image" {
5757

5858
resource "aws_lambda_function" "lambda_copy_image" {
5959
filename = "lambdas.zip"
60-
function_name = "tf-copy-image"
60+
function_name = "ce-copy-image"
6161
role = "${aws_iam_role.iam_for_lambda.arn}"
6262
handler = "copy_image.lambda_handler"
6363
source_code_hash = "${data.archive_file.lambdas.output_base64sha256}"
@@ -67,7 +67,7 @@ resource "aws_lambda_function" "lambda_copy_image" {
6767

6868
resource "aws_lambda_function" "lambda_get_copy_status" {
6969
filename = "lambdas.zip"
70-
function_name = "tf-get-copy-status"
70+
function_name = "ce-get-copy-status"
7171
role = "${aws_iam_role.iam_for_lambda.arn}"
7272
handler = "get_copy_status.lambda_handler"
7373
source_code_hash = "${data.archive_file.lambdas.output_base64sha256}"
@@ -77,7 +77,7 @@ resource "aws_lambda_function" "lambda_get_copy_status" {
7777

7878
resource "aws_lambda_function" "lambda_split_image" {
7979
filename = "lambdas.zip"
80-
function_name = "tf-split-image"
80+
function_name = "ce-split-image"
8181
role = "${aws_iam_role.iam_for_lambda.arn}"
8282
handler = "split_image.lambda_handler"
8383
source_code_hash = "${data.archive_file.lambdas.output_base64sha256}"
@@ -87,7 +87,7 @@ resource "aws_lambda_function" "lambda_split_image" {
8787

8888
resource "aws_lambda_function" "lambda_image_cleanup" {
8989
filename = "lambdas.zip"
90-
function_name = "tf-image-cleanup"
90+
function_name = "ce-image-cleanup"
9191
role = "${aws_iam_role.iam_for_lambda.arn}"
9292
handler = "image_cleanup.lambda_handler"
9393
source_code_hash = "${data.archive_file.lambdas.output_base64sha256}"

step/step-function.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
resource "aws_sfn_state_machine" "rehost_migration" {
2-
name = "tf-rehost-migration"
3-
role_arn = "${aws_iam_role.iam_for_stepfunction.arn}"
2+
name = "ce-rehost-migration"
3+
role_arn = "${aws_iam_role.iam_for_stepfunction.arn}"
44

55
definition = <<EOF
66
{

step/variable.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
variable "region" {
22
default = "us-east-1"
33
description = "The AWS region to be used."
4-
type = "string"
4+
type = string
5+
}
6+
7+
variable "assume_role_list" {
8+
default = []
9+
description = ""
10+
type = list(string)
511
}

0 commit comments

Comments
 (0)