Skip to content

Commit a746f5b

Browse files
new: added policy ecc-aws-576-ec2_instance_dedicated_tenancy
1 parent 4ad2fb0 commit a746f5b

File tree

13 files changed

+590
-0
lines changed

13 files changed

+590
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) 2023 EPAM Systems, Inc.
2+
#
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
7+
8+
policies:
9+
- name: ecc-aws-576-ec2_instance_dedicated_tenancy
10+
comment: '010006032000'
11+
description: |
12+
Amazon EC2 instances with dedicated tenancy
13+
resource: aws.ec2
14+
filters:
15+
- type: value
16+
key: Placement.Tenancy
17+
op: in
18+
value:
19+
- dedicated
20+
- host
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
resource "aws_instance" "this" {
2+
ami = data.aws_ami.this.id
3+
instance_type = "a1.medium"
4+
vpc_security_group_ids = ["${aws_security_group.this.id}"]
5+
subnet_id = data.aws_subnets.this.ids[0]
6+
tags = {
7+
Name = "576_instance_green"
8+
}
9+
}
10+
11+
data "aws_ami" "this" {
12+
most_recent = true
13+
owners = ["amazon"]
14+
filter {
15+
name = "architecture"
16+
values = ["arm64"]
17+
}
18+
filter {
19+
name = "name"
20+
values = ["amzn2-ami-hvm*"]
21+
}
22+
}
23+
24+
data "aws_vpc" "default" {
25+
default = true
26+
}
27+
28+
data "aws_subnets" "this" {
29+
filter {
30+
name = "vpc-id"
31+
values = [data.aws_vpc.default.id]
32+
}
33+
}
34+
35+
resource "aws_security_group" "this" {
36+
name = "576_sg_green"
37+
description = "576_sg_green"
38+
vpc_id = data.aws_vpc.default.id
39+
40+
egress {
41+
from_port = 0
42+
to_port = 0
43+
protocol = "-1"
44+
cidr_blocks = ["0.0.0.0/0"]
45+
}
46+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 4"
6+
}
7+
}
8+
}
9+
10+
provider "aws" {
11+
profile = var.profile
12+
region = var.default-region
13+
14+
default_tags {
15+
tags = {
16+
CustodianRule = "ecc-aws-576-ec2_instance_dedicated_tenancy"
17+
ComplianceStatus = "Green"
18+
}
19+
}
20+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
profile = "c7n"
2+
default-region = "us-east-1"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
variable "default-region" {
2+
type = string
3+
description = "Default region for resources will be created"
4+
}
5+
6+
variable "profile" {
7+
type = string
8+
description = "Profile name configured before running apply"
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Effect": "Allow",
6+
"Action": [
7+
"ec2:DescribeInstances"
8+
],
9+
"Resource": "*"
10+
}
11+
]
12+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
resource "aws_instance" "this" {
2+
ami = data.aws_ami.this.id
3+
instance_type = "a1.medium"
4+
vpc_security_group_ids = ["${aws_security_group.this.id}"]
5+
subnet_id = data.aws_subnets.this.ids[0]
6+
tenancy = "dedicated"
7+
tags = {
8+
Name = "576_instance_red"
9+
}
10+
}
11+
12+
data "aws_ami" "this" {
13+
most_recent = true
14+
owners = ["amazon"]
15+
filter {
16+
name = "architecture"
17+
values = ["arm64"]
18+
}
19+
filter {
20+
name = "name"
21+
values = ["amzn2-ami-hvm*"]
22+
}
23+
}
24+
25+
data "aws_vpc" "default" {
26+
default = true
27+
}
28+
29+
data "aws_subnets" "this" {
30+
filter {
31+
name = "vpc-id"
32+
values = [data.aws_vpc.default.id]
33+
}
34+
}
35+
36+
resource "aws_security_group" "this" {
37+
name = "576_sg_red"
38+
description = "576_sg_red"
39+
vpc_id = data.aws_vpc.default.id
40+
41+
egress {
42+
from_port = 0
43+
to_port = 0
44+
protocol = "-1"
45+
cidr_blocks = ["0.0.0.0/0"]
46+
}
47+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 4"
6+
}
7+
}
8+
}
9+
10+
provider "aws" {
11+
profile = var.profile
12+
region = var.default-region
13+
14+
default_tags {
15+
tags = {
16+
CustodianRule = "ecc-aws-576-ec2_instance_dedicated_tenancy"
17+
ComplianceStatus = "Red"
18+
}
19+
}
20+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
profile = "c7n"
2+
default-region = "us-east-1"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
variable "default-region" {
2+
type = string
3+
description = "Default region for resources will be created"
4+
}
5+
6+
variable "profile" {
7+
type = string
8+
description = "Profile name configured before running apply"
9+
}

0 commit comments

Comments
 (0)