-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sudoblark/feature/initial-setup
Initial module setup
- Loading branch information
Showing
15 changed files
with
370 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
locals { | ||
actual_iam_policy_documents = { | ||
for state_machine in var.raw_state_machines : | ||
state_machine.suffix => { | ||
statements = concat(state_machine.iam_policy_statements, local.barebones_statemachine_statements, | ||
[ | ||
{ | ||
sid = "ListOwnExecutions", | ||
actions = [ | ||
"states:ListExecutions" | ||
] | ||
resources = [ | ||
format( | ||
"arn:aws:states:%s:%s:stateMachine:%s-%s-%s-stepfunction", | ||
lower(data.aws_region.current_region.name), | ||
lower(data.aws_caller_identity.current_account.id), | ||
lower(var.environment), | ||
lower(var.application_name), | ||
lower(state_machine.suffix) | ||
) | ||
] | ||
conditions = [] | ||
}, | ||
{ | ||
sid = "AllowCloudwatchStreamAccess", | ||
actions = [ | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents" | ||
], | ||
resources = [ | ||
"arn:aws:logs:${data.aws_region.current_region.name}:${data.aws_caller_identity.current_account.account_id}:log-group:/aws/stepfunction/${format("%s-%s-%s-stepfunction", var.environment, var.application_name, state_machine.suffix)}", | ||
"arn:aws:logs:${data.aws_region.current_region.name}:${data.aws_caller_identity.current_account.account_id}:log-group:/aws/stepfunction/${format("%s-%s-%s-stepfunction", var.environment, var.application_name, state_machine.suffix)}:*" | ||
] | ||
conditions = [] | ||
}, | ||
{ | ||
sid = "AllowCloudwatchLogDelivery", | ||
actions = [ | ||
"logs:CreateLogDelivery", | ||
"logs:PutResourcePolicy", | ||
"logs:UpdateLogDelivery", | ||
"logs:DeleteLogDelivery", | ||
"logs:DescribeResourcePolicies", | ||
"logs:GetLogDelivery", | ||
"logs:ListLogDeliveries", | ||
"logs:DescribeLogGroups" | ||
], | ||
resources = ["*"] | ||
conditions = [] | ||
} | ||
] | ||
) | ||
} | ||
} | ||
} | ||
|
||
data "aws_iam_policy_document" "attached_policies" { | ||
for_each = local.actual_iam_policy_documents | ||
|
||
dynamic "statement" { | ||
for_each = each.value["statements"] | ||
|
||
content { | ||
sid = statement.value["sid"] | ||
actions = statement.value["actions"] | ||
resources = statement.value["resources"] | ||
|
||
dynamic "condition" { | ||
for_each = statement.value["conditions"] | ||
|
||
content { | ||
test = condition.value["test"] | ||
variable = condition.value["variable"] | ||
values = condition.value["values"] | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
locals { | ||
barebones_statemachine_statements = [ | ||
{ | ||
sid = "BarebonesEventActionsForStatemachine" | ||
actions = [ | ||
"events:PutEvents", | ||
"events:DescribeRule", | ||
"events:PutRule", | ||
"events:PutTargets" | ||
] | ||
resources = [ | ||
"arn:aws:events:${data.aws_region.current_region.name}:${data.aws_caller_identity.current_account.account_id}:rule/default/StepFunctionsGetEventsForECSTaskRule", | ||
"arn:aws:events:${data.aws_region.current_region.name}:${data.aws_caller_identity.current_account.account_id}:rule/StepFunctionsGetEventsForECSTaskRule", | ||
"arn:aws:events:${data.aws_region.current_region.name}:${data.aws_caller_identity.current_account.account_id}:event-bus/default" | ||
] | ||
conditions = [] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Get current region | ||
data "aws_region" "current_region" {} | ||
|
||
# Retrieve the current AWS Account info | ||
data "aws_caller_identity" "current_account" {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Get current region | ||
data "aws_region" "current_region" {} | ||
|
||
# Retrieve the current AWS Account info | ||
data "aws_caller_identity" "current_account" {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"Comment": "A Hello World example of the Amazon States Language using an AWS Lambda Function", | ||
"StartAt": "HelloWorld", | ||
"States": { | ||
"HelloWorld": { | ||
"Type": "Task", | ||
"Resource": "${lambda-arn}", | ||
"End": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
locals { | ||
raw_state_machines = [ | ||
{ | ||
suffix : "hello-world", | ||
template_file : "${path.module}/files/step-function.json", | ||
template_input : { | ||
"lambda-arn" : "arn:aws:lambda:${data.aws_region.current_region.name}:${data.aws_caller_identity.current_account.account_id}:function:hello-world-function" | ||
}, | ||
iam_policy_statements : [ | ||
{ | ||
sid : "AllowLambdaExecution", | ||
actions : [ | ||
"lambda:InvokeFunction", | ||
"lambda:InvokeAsync", | ||
], | ||
resources : [ | ||
"arn:aws:lambda:${data.aws_region.current_region.name}:${data.aws_caller_identity.current_account.account_id}:function:hello-world-function" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.61.0" | ||
} | ||
} | ||
required_version = "~> 1.5.0" | ||
} | ||
|
||
provider "aws" { | ||
region = "eu-west-2" | ||
} | ||
|
||
module "step_function" { | ||
source = "github.com/sudoblark/sudoblark.terraform.module.aws.state_machine?ref=1.0.0" | ||
|
||
application_name = var.application_name | ||
environment = var.environment | ||
raw_state_machines = local.raw_state_machines | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
variable "environment" { | ||
description = "Which environment this is being instantiated in." | ||
type = string | ||
validation { | ||
condition = contains(["dev", "test", "prod"], var.environment) | ||
error_message = "Must be either dev, test or prod" | ||
} | ||
default = "prod" | ||
} | ||
|
||
variable "application_name" { | ||
description = "Name of the application utilising the resource resource." | ||
type = string | ||
default = "demo-app" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.61.0" | ||
} | ||
} | ||
required_version = "~> 1.5.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
locals { | ||
actual_state_machines = { | ||
for state_machine in var.raw_state_machines : | ||
state_machine.suffix => merge(state_machine, { | ||
state_machine_definition = templatefile(state_machine.template_file, state_machine.template_input) | ||
policy_json = data.aws_iam_policy_document.attached_policies[state_machine.suffix].json | ||
state_machine_name = format("%s-%s-%s-stepfunction", var.environment, var.application_name, state_machine.suffix) | ||
}) | ||
} | ||
} | ||
|
||
module "step_function_state_machine" { | ||
for_each = local.actual_state_machines | ||
|
||
depends_on = [ | ||
data.aws_iam_policy_document.attached_policies | ||
] | ||
|
||
|
||
source = "terraform-aws-modules/step-functions/aws" | ||
version = "4.2.0" | ||
|
||
name = each.value["state_machine_name"] | ||
create_role = true | ||
policy_jsons = [each.value["policy_json"]] | ||
|
||
definition = each.value["state_machine_definition"] | ||
|
||
logging_configuration = { | ||
"include_execution_data" = true | ||
"level" = "ALL" | ||
} | ||
cloudwatch_log_group_name = "/aws/vendedlogs/states/${each.value["state_machine_name"]}" | ||
cloudwatch_log_group_retention_in_days = each.value["cloudwatch_retention"] | ||
|
||
service_integrations = { | ||
stepfunction_Sync = { | ||
# Set to true to use the default events (otherwise, set this to a list of ARNs; see the docs linked in locals.tf | ||
# for more information). Without events permissions, you will get an error similar to this: | ||
# Error: AccessDeniedException: 'arn:aws:iam::xxxx:role/step-functions-role' is not authorized to | ||
# create managed-rule | ||
events = true | ||
} | ||
} | ||
} |
Oops, something went wrong.