Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config Organization Solution #229

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,10 @@ def orchestrator(event: Dict[str, Any], context: Any) -> None:
event: event data
context: runtime information
"""
if event.get("RequestType"):
if event.get("Terraform"):
LOGGER.info("...calling terraform handler...")
process_event_cloudformation(event, context)
elif event.get("RequestType"):
LOGGER.info("...calling helper...")
helper(event, context)
elif event.get("Records") and event["Records"][0]["EventSource"] == "aws:sns":
Expand Down
3 changes: 2 additions & 1 deletion aws_sra_examples/terraform/common/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ resource "local_file" "config_file_creation" {
enable_cloudtrail_org = false
enable_iam_password_policy = false
enable_inspector = false

enable_config_org = false

########################################################################
# Guard Duty Settings
########################################################################
Expand Down
8 changes: 7 additions & 1 deletion aws_sra_examples/terraform/common/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
########################################################################
variable "account_region" {
type = string
description = "Default Account Region to deploy in"
default = "us-east-1"
}

variable "control_tower" {
description = "AWS Control Tower landing zone deployed/in-use"
default = "true"
default = "false"
}

variable "governed_regions" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ resource "aws_lambda_function" "cloudtrail_org_lambda_function" {
#checkov:skip=CKV_AWS_115: Ensure that AWS Lambda function is configured for function-level concurrent execution limit
#checkov:skip=CKV_AWS_117: Ensure that AWS Lambda function is configured inside a VPC
#checkov:skip=CKV_AWS_50: X-Ray tracing is enabled for Lambda

description = "Creates an Organization CloudTrail"
function_name = var.cloudtrail_lambda_function_name
role = aws_iam_role.cloudtrail_lambda_role.arn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ resource "aws_s3_bucket_policy" "org_trail_bucket_policy" {
resource "aws_secretsmanager_secret" "org_trail_s3_bucket_secret" {
#checkov:skip=CKV_AWS_149: Ensure that Secrets Manager secret is encrypted using KMS CMK
#checkov:skip=CKV2_AWS_57: Ensure Secrets Manager secrets should have automatic rotation enabled

count = var.sra_secrets_key_alias_arn != "" ? 1 : 0

name = "sra/cloudtrail_org_s3_bucket"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
########################################################################
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
########################################################################

data "aws_partition" "current" {}
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
data "aws_organizations_organization" "current" {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
########################################################################
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
########################################################################
resource "aws_iam_role" "r_config_aggregator_role" {
name = var.p_aggregator_role_name
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = "sts:AssumeRole"
Principal = {
Service = "config.amazonaws.com"
}
}
]
})

managed_policy_arns = [
"arn:aws:iam::aws:policy/service-role/AWSConfigRoleForOrganizations"
]

tags = {
"${var.p_sra_solution_name_key}" = var.p_sra_solution_name
}
}

resource "aws_config_configuration_aggregator" "r_organization_config_aggregator" {
name = var.p_aggregator_name

account_aggregation_source {
account_ids = [data.aws_caller_identity.current.account_id]
all_regions = true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
########################################################################
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
########################################################################

terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.1.0"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
########################################################################
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
########################################################################
variable "p_aggregator_name" {
type = string
description = "Config Aggregator Name"
default = "sra-config-aggregator-org"
}

variable "p_aggregator_role_name" {
type = string
description = "Config Aggregator Role Name"
default = "sra-config-aggregator-org"
}

variable "p_sra_solution_name" {
type = string
description = "The SRA solution name. The default value is the folder name of the solution"
default = "sra-config-aggregator-org"
}

variable "p_sra_solution_name_key" {
type = string
description = "The key used for tagging resources with the SRA solution name."
default = "sra-solution"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
########################################################################
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
########################################################################

data "aws_partition" "current" {}
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
data "aws_organizations_organization" "current" {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
########################################################################
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
########################################################################

resource "aws_lambda_invocation" "new_lambda_invoke" {
function_name = aws_lambda_function.r_config_org_lambda_function.function_name

input = jsonencode({
"Terraform" : "true",
"RequestType" : "Create",
"ResourceType" : "Custom::LambdaCustomResource",
"ResourceProperties" : {
"ServiceToken" : "${aws_lambda_function.r_config_org_lambda_function.arn}",
"AUDIT_ACCOUNT" : "${var.p_audit_account_id}",
"CONFIGURATION_ROLE_NAME" : "${var.p_config_configuration_role_name}",
"CONTROL_TOWER_REGIONS_ONLY" : "${var.p_control_tower_regions_only}",
"ENABLED_REGIONS" : "${var.p_enabled_regions}",
"ALL_SUPPORTED" : "${var.p_all_supported}",
"INCLUDE_GLOBAL_RESOURCE_TYPES" : "${var.p_include_global_resource_types}",
"DELIVERY_CHANNEL_NAME" : "${var.p_delivery_channel_name}",
"FREQUENCY" : "${var.p_frequency}",
"RESOURCE_TYPES" : "${var.p_resource_types}",
"RECORDER_NAME" : "${var.p_recorder_name}",
"KMS_KEY_SECRET_NAME" : "${var.p_kms_key_arn_secret_name}",
"HOME_REGION" : "${var.p_home_region}",
"SNS_TOPIC_ARN_FANOUT" : "${aws_sns_topic.r_config_org_topic.arn}",
"PUBLISHING_DESTINATION_BUCKET_ARN" : "arn:aws:s3:::${var.p_publishing_destination_bucket_name}"
}
})
}
Loading
Loading