Skip to content

Commit

Permalink
skip: Merge branch 'policy_testing_2' into feature/policy_testing
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-shcherbak committed May 21, 2024
2 parents 3f18677 + 7c0e7e1 commit 54a0550
Show file tree
Hide file tree
Showing 28 changed files with 257 additions and 47 deletions.
4 changes: 4 additions & 0 deletions auto_policy_testing/green/common_resources/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ output "vpc_subnet_3_id" {
output "kms_key_arn" {
value = aws_kms_key.this.arn
}

output "wafregional_acl_id" {
value = aws_wafregional_web_acl.this.id
}
9 changes: 9 additions & 0 deletions auto_policy_testing/green/launch/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
data "aws_ami" "this" {
most_recent = true
owners = ["amazon"]

filter {
name = "name"
values = ["amzn2-ami-hvm*"]
}
}
12 changes: 12 additions & 0 deletions auto_policy_testing/green/launch/launch.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
resource "aws_launch_configuration" "this" {
name_prefix = "${module.naming.resource_prefix.launch_config}"
image_id = data.aws_ami.this.id
instance_type = "t2.micro"
associate_public_ip_address = false

metadata_options {
http_endpoint = "enabled"
http_tokens = "required"
http_put_response_hop_limit = "1"
}
}
13 changes: 13 additions & 0 deletions auto_policy_testing/green/launch/main.tf
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"
}
}
5 changes: 5 additions & 0 deletions auto_policy_testing/green/launch/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
output "launch" {
value = {
launch-config = aws_launch_configuration.this.name
}
}
16 changes: 16 additions & 0 deletions auto_policy_testing/green/launch/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5"
}
}
}

provider "aws" {
region = var.region
default_tags {
tags = module.naming.default_tags
}
}

5 changes: 5 additions & 0 deletions auto_policy_testing/green/launch/variables.tf
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"
}
1 change: 1 addition & 0 deletions auto_policy_testing/green/peering-connection/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data "aws_caller_identity" "this" {}
13 changes: 13 additions & 0 deletions auto_policy_testing/green/peering-connection/main.tf
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"
}
}
5 changes: 5 additions & 0 deletions auto_policy_testing/green/peering-connection/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
output "peering-connection" {
value = {
peering-connection = aws_vpc_peering_connection.this.id
}
}
14 changes: 14 additions & 0 deletions auto_policy_testing/green/peering-connection/peering_connection.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "aws_vpc_peering_connection" "this" {
peer_owner_id = data.aws_caller_identity.this.account_id
peer_vpc_id = aws_vpc.vpc1.id
vpc_id = aws_vpc.vpc2.id
auto_accept = true
}

resource "aws_vpc" "vpc1" {
cidr_block = "10.1.0.0/16"
}

resource "aws_vpc" "vpc2" {
cidr_block = "10.2.0.0/16"
}
16 changes: 16 additions & 0 deletions auto_policy_testing/green/peering-connection/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5"
}
}
}

provider "aws" {
region = var.region
default_tags {
tags = module.naming.default_tags
}
}

5 changes: 5 additions & 0 deletions auto_policy_testing/green/peering-connection/variables.tf
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"
}
50 changes: 4 additions & 46 deletions auto_policy_testing/red/directory/directory.tf
Original file line number Diff line number Diff line change
@@ -1,60 +1,18 @@

resource "aws_directory_service_directory" "this" {
name = "DirectoryService.example.com"
name = "${module.naming.resource_prefix.directory}.com"
password = "#S1ncerely"
size = "Small"

vpc_settings {
vpc_id = aws_vpc.this.id
vpc_id = data.terraform_remote_state.common.outputs.vpc_id
subnet_ids = [
aws_subnet.this1.id,
aws_subnet.this2.id
data.terraform_remote_state.common.outputs.vpc_subnet_1_id,
data.terraform_remote_state.common.outputs.vpc_subnet_3_id
]
}
}

resource "aws_vpc" "this" {
cidr_block = "10.0.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true
}

resource "aws_subnet" "this1" {
vpc_id = aws_vpc.this.id
cidr_block = "10.0.1.0/24"
availability_zone_id = "use1-az2"
map_public_ip_on_launch = "true"
}

resource "aws_subnet" "this2" {
vpc_id = aws_vpc.this.id
cidr_block = "10.0.2.0/24"
availability_zone_id = "use1-az4"
map_public_ip_on_launch = "true"
}

resource "aws_internet_gateway" "this" {
vpc_id = aws_vpc.this.id
}

resource "aws_route_table" "this" {
vpc_id = aws_vpc.this.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.this.id
}
}

resource "aws_route_table_association" "this" {
subnet_id = aws_subnet.this1.id
route_table_id = aws_route_table.this.id
}

resource "aws_route_table_association" "this2" {
subnet_id = aws_subnet.this2.id
route_table_id = aws_route_table.this.id
}


# # ecc-aws-147-ebs_volume_without_encrypt
# # ecc-aws-570-ebs_volumes_are_of_type_gp3_instead_of_io1
Expand Down
2 changes: 1 addition & 1 deletion auto_policy_testing/red/directory/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
output "directory" {
value = {
directory = aws_directory_service_directory.this.id
directory = aws_directory_service_directory.this.id
}
}
9 changes: 9 additions & 0 deletions auto_policy_testing/red/launch/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
data "aws_ami" "this" {
most_recent = true
owners = ["amazon"]

filter {
name = "name"
values = ["amzn2-ami-hvm*"]
}
}
25 changes: 25 additions & 0 deletions auto_policy_testing/red/launch/launch.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
resource "aws_launch_configuration" "this" {
name_prefix = "${module.naming.resource_prefix.launch_config}"
image_id = data.aws_ami.this.id
instance_type = "t2.micro"
associate_public_ip_address = true

# metadata_options {
# http_endpoint = "enabled"
# http_tokens = "required"
# http_put_response_hop_limit = "5"
# }
}

resource "aws_launch_configuration" "this2" {
name_prefix = "${module.naming.resource_prefix.launch_config}-2"
image_id = data.aws_ami.this.id
instance_type = "t2.micro"
associate_public_ip_address = true

metadata_options {
http_endpoint = "enabled"
http_tokens = "required"
http_put_response_hop_limit = "5"
}
}
13 changes: 13 additions & 0 deletions auto_policy_testing/red/launch/main.tf
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"
}
}
6 changes: 6 additions & 0 deletions auto_policy_testing/red/launch/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
output "launch" {
value = {
launch-config = aws_launch_configuration.this.name
ecc-aws-520-autoscaling_launch_config_hop_limit = aws_launch_configuration.this2.name
}
}
16 changes: 16 additions & 0 deletions auto_policy_testing/red/launch/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5"
}
}
}

provider "aws" {
region = var.region
default_tags {
tags = module.naming.default_tags
}
}

5 changes: 5 additions & 0 deletions auto_policy_testing/red/launch/variables.tf
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"
}
1 change: 1 addition & 0 deletions auto_policy_testing/red/peering-connection/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data "aws_caller_identity" "this" {}
13 changes: 13 additions & 0 deletions auto_policy_testing/red/peering-connection/main.tf
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"
}
}
5 changes: 5 additions & 0 deletions auto_policy_testing/red/peering-connection/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
output "peering-connection" {
value = {
peering-connection = aws_vpc_peering_connection.this.id
}
}
15 changes: 15 additions & 0 deletions auto_policy_testing/red/peering-connection/peering_connection.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
resource "aws_vpc_peering_connection" "this" {
peer_owner_id = data.aws_caller_identity.this.account_id
peer_vpc_id = aws_vpc.vpc1.id
vpc_id = aws_vpc.vpc2.id
auto_accept = true
provider = aws.provider2
}

resource "aws_vpc" "vpc1" {
cidr_block = "10.1.0.0/16"
}

resource "aws_vpc" "vpc2" {
cidr_block = "10.2.0.0/16"
}
20 changes: 20 additions & 0 deletions auto_policy_testing/red/peering-connection/provider.tf
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"
}
5 changes: 5 additions & 0 deletions auto_policy_testing/red/peering-connection/variables.tf
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"
}
1 change: 1 addition & 0 deletions auto_policy_testing/shared_tf_modules/naming/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ output "resource_prefix" {
value = {
acm = "${local.suffix}.${local.compliance_status}"
# cloud_trail = "${local.suffix}_${var.resource_type}_cloudtrail_${local.compliance_status}"
launch_config = "${local.suffix}_${var.resource_type}_launch_config_${local.compliance_status}"
nat_gateway = "${local.suffix}_${var.resource_type}_ng_${local.compliance_status}"
eks = "${local.suffix}_${var.resource_type}_eks_${local.compliance_status}"
fsx = "${local.suffix}_${var.resource_type}_fsx_${local.compliance_status}"
Expand Down

0 comments on commit 54a0550

Please sign in to comment.