-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68a56d0
commit d8faca2
Showing
14 changed files
with
180 additions
and
147 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 |
---|---|---|
|
@@ -8,5 +8,4 @@ resource "null_resource" "this" { | |
when = destroy | ||
command = "aws securityhub disable-security-hub" | ||
} | ||
|
||
} |
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,49 @@ | ||
resource "aws_iam_role" "this" { | ||
name = "${module.naming.resource_prefix.iam_role}" | ||
assume_role_policy = <<-POLICY | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "cloudtrail.amazonaws.com" | ||
}, | ||
"Action": "sts:AssumeRole" | ||
} | ||
] | ||
} | ||
POLICY | ||
} | ||
|
||
resource "aws_iam_role_policy" "this" { | ||
name = "${module.naming.resource_prefix.iam_policy}" | ||
role = aws_iam_role.this.id | ||
policy = <<-POLICY | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Sid": "AWSCloudTrailCreateLogStream2014110", | ||
"Effect": "Allow", | ||
"Action": [ | ||
"logs:CreateLogStream" | ||
], | ||
"Resource": [ | ||
"arn:aws:logs:${var.region}:${data.aws_caller_identity.this.account_id}:log-group:${aws_cloudwatch_log_group.this.name}:log-stream:*" | ||
] | ||
}, | ||
{ | ||
"Sid": "AWSCloudTrailPutLogEvents20141101", | ||
"Effect": "Allow", | ||
"Action": [ | ||
"logs:PutLogEvents" | ||
], | ||
"Resource": [ | ||
"arn:aws:logs:${var.region}:${data.aws_caller_identity.this.account_id}:log-group:${aws_cloudwatch_log_group.this.name}:log-stream:*" | ||
] | ||
} | ||
] | ||
} | ||
POLICY | ||
} |
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,13 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
SECURITY_GROUP_ID="sg-06309cf09c4be9423" | ||
|
||
RULE_IDS=$(aws ec2 describe-security-group-rules --filters Name="group-id",Values="$SECURITY_GROUP_ID" --query 'SecurityGroupRules[?CidrIpv4==`0.0.0.0/0` && IsEgress==`false`]'.SecurityGroupRuleId --output text) | ||
|
||
for RULE_ID in $RULE_IDS | ||
do | ||
OLD_RULE=$(aws ec2 describe-security-group-rules --security-group-rule-ids $RULE_ID --output json --query "SecurityGroupRules[0].{IpProtocol:IpProtocol,FromPort:FromPort,ToPort:ToPort,CidrIpv4:CidrIpv4}") | ||
UPD_RULE=$(echo $OLD_RULE | sed 's|"0.0.0.0/0"|"10.0.2.0/24"|g') | ||
aws ec2 modify-security-group-rules --group-id $SECURITY_GROUP_ID --security-group-rules "[{\"SecurityGroupRuleId\": \"$RULE_ID\",\"SecurityGroupRule\": $UPD_RULE}]" | ||
done |
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,40 @@ | ||
|
||
resource "aws_directory_service_directory" "this" { | ||
name = "${module.naming.resource_prefix.directory}.com" | ||
password = "#S1ncerely" | ||
size = "Small" | ||
|
||
vpc_settings { | ||
vpc_id = data.terraform_remote_state.common.outputs.vpc_id | ||
subnet_ids = [ | ||
data.terraform_remote_state.common.outputs.vpc_subnet_1_id, | ||
data.terraform_remote_state.common.outputs.vpc_subnet_3_id | ||
] | ||
} | ||
} | ||
|
||
resource "null_resource" "this" { | ||
depends_on = [ | ||
aws_directory_service_directory.this | ||
] | ||
triggers = { | ||
sg = aws_directory_service_directory.this.security_group_id | ||
} | ||
provisioner "local-exec" { | ||
interpreter = ["/bin/bash", "-c"] | ||
command = <<EOF | ||
set -e | ||
SECURITY_GROUP_ID=${self.triggers.sg} | ||
RULE_IDS=$(aws ec2 describe-security-group-rules --filters Name="group-id",Values="$SECURITY_GROUP_ID" --query 'SecurityGroupRules[?CidrIpv4==`0.0.0.0/0` && IsEgress==`false`]'.SecurityGroupRuleId --output text) | ||
for RULE_ID in $RULE_IDS | ||
do | ||
OLD_RULE=$(aws ec2 describe-security-group-rules --security-group-rule-ids $RULE_ID --output json --query "SecurityGroupRules[0].{IpProtocol:IpProtocol,FromPort:FromPort,ToPort:ToPort,CidrIpv4:CidrIpv4}") | ||
UPD_RULE=$(echo $OLD_RULE | sed 's|"0.0.0.0/0"|"10.0.2.0/24"|g') | ||
aws ec2 modify-security-group-rules --group-id $SECURITY_GROUP_ID --security-group-rules "[{\"SecurityGroupRuleId\": \"$RULE_ID\",\"SecurityGroupRule\": $UPD_RULE}]" | ||
done | ||
EOF | ||
} | ||
} |
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,13 @@ | ||
module "naming" { | ||
source = "../../shared_tf_modules/naming" | ||
resource_type = basename(abspath(path.module)) | ||
status = title(basename(dirname(abspath(path.module)))) | ||
} | ||
|
||
data "terraform_remote_state" "common" { | ||
backend = "local" | ||
|
||
config = { | ||
path = "../common_resources/terraform.tfstate" | ||
} | ||
} |
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 @@ | ||
output "directory" { | ||
value = { | ||
directory = aws_directory_service_directory.this.id | ||
} | ||
} |
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,20 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5" | ||
} | ||
} | ||
} | ||
|
||
provider "aws" { | ||
region = var.region | ||
default_tags { | ||
tags = module.naming.default_tags | ||
} | ||
} | ||
|
||
provider "aws" { | ||
region = var.region | ||
alias = "provider2" | ||
} |
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 @@ | ||
variable "region" { | ||
type = string | ||
description = "Region where resources will be created" | ||
default = "us-east-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
Oops, something went wrong.