Skip to content

Commit 5e82e79

Browse files
author
Nikita Dugar
authored
Merge pull request #1 from clouddrove/CD-90
Cd 90
2 parents b90c90e + 07dd62a commit 5e82e79

File tree

5 files changed

+155
-71
lines changed

5 files changed

+155
-71
lines changed

.github/workflows/terraform.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: 'Terraform GitHub Actions'
2+
on:
3+
- pull_request
4+
5+
jobs:
6+
terraform:
7+
name: 'Terraform'
8+
runs-on: ubuntu-latest
9+
steps:
10+
11+
- name: 'Checkout'
12+
uses: actions/checkout@master
13+
14+
- name: 'Terraform Format'
15+
uses: clouddrove/github-actions@v2.0
16+
with:
17+
actions_subcommand: 'fmt'
18+
19+
- name: 'Terraform Init'
20+
uses: clouddrove/github-actions@v2.0
21+
with:
22+
actions_subcommand: 'init'
23+
tf_actions_working_dir: ./_example
24+
25+
- name: Configure AWS Credentials
26+
uses: clouddrove/configure-aws-credentials@v1
27+
with:
28+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
29+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
30+
aws-region: us-east-2
31+
32+
- name: 'Terraform Plan'
33+
uses: clouddrove/github-actions@v2.0
34+
with:
35+
actions_subcommand: 'plan'
36+
tf_actions_working_dir: ./_example
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: 'Terratest'
41+
uses: clouddrove/github-actions@v2.0
42+
with:
43+
actions_subcommand: 'terratest'
44+
tf_actions_working_dir: ./_test
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
48+
- name: 'Slack Notification'
49+
uses: clouddrove/action-slack@v2
50+
with:
51+
status: ${{ job.status }}
52+
fields: repo,author
53+
author_name: 'Clouddrove'
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required
56+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required
57+
if: always()

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ This module has a few dependencies:
7272
Here is an example of how you can use this module in your inventory structure:
7373
```hcl
7474
module "alb" {
75-
source = "git::https://github.com/clouddrove/terraform-aws-alb.git?ref=tags/0.12.2"
75+
source = "git::https://github.com/clouddrove/terraform-aws-alb.git?ref=tags/0.12.3"
76+
7677
name = "alb"
7778
application = "clouddrove"
7879
environment = "test"
@@ -90,6 +91,8 @@ Here is an example of how you can use this module in your inventory structure:
9091
listener_certificate_arn = "arn:aws:acm:eu-west-1:xxxxxxxxxxxx:certificate/xxxxxx-xxxx-xxxxx-xxxx"
9192
https_enabled = true
9293
http_enabled = true
94+
https_port = 443
95+
listener_type = "forward"
9396
}
9497
```
9598

README.yaml

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,26 @@ usage : |-
3535
### Simple Example
3636
Here is an example of how you can use this module in your inventory structure:
3737
```hcl
38-
module "alb" {
39-
source = "git::https://github.com/clouddrove/terraform-aws-alb.git?ref=tags/0.12.2"
40-
name = "alb"
41-
application = "clouddrove"
42-
environment = "test"
43-
label_order = ["environment", "name", "application"]
44-
internal = false
45-
load_balancer_type = "application"
46-
instance_count = 2
47-
security_groups = ["sg-xxxxxxx"]
48-
subnets = "subnet-xxxxxxx"
49-
enable_deletion_protection = false
50-
target_id = "i-xxxxxxxxxx"
51-
vpc_id = "vpc-xxxxxxxxx"
52-
target_group_protocol = "HTTP"
53-
target_group_port = 80
54-
listener_certificate_arn = "arn:aws:acm:eu-west-1:xxxxxxxxxxxx:certificate/xxxxxx-xxxx-xxxxx-xxxx"
55-
https_enabled = true
56-
http_enabled = true
57-
}
38+
module "alb" {
39+
source = "git::https://github.com/clouddrove/terraform-aws-alb.git?ref=tags/0.12.3"
40+
name = "alb"
41+
application = "clouddrove"
42+
environment = "test"
43+
label_order = ["environment", "name", "application"]
44+
internal = false
45+
load_balancer_type = "application"
46+
instance_count = 2
47+
security_groups = ["sg-xxxxxxx"]
48+
subnets = "subnet-xxxxxxx"
49+
enable_deletion_protection = false
50+
target_id = "i-xxxxxxxxxx"
51+
vpc_id = "vpc-xxxxxxxxx"
52+
target_group_protocol = "HTTP"
53+
target_group_port = 80
54+
listener_certificate_arn = "arn:aws:acm:eu-west-1:xxxxxxxxxxxx:certificate/xxxxxx-xxxx-xxxxx-xxxx"
55+
https_enabled = true
56+
http_enabled = true
57+
https_port = 443
58+
listener_type = "forward"
59+
}
5860
```

_example/example.tf

Lines changed: 71 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,111 +2,134 @@ provider "aws" {
22
region = "eu-west-1"
33
}
44

5-
module "keypair" {
6-
source = "git::https://github.com/clouddrove/terraform-aws-keypair.git?ref=tags/0.12.2"
7-
8-
key_path = "~/.ssh/id_rsa.pub"
9-
key_name = "main-key"
10-
enable_key_pair = true
11-
}
125

136
module "vpc" {
147
source = "git::https://github.com/clouddrove/terraform-aws-vpc.git?ref=tags/0.12.4"
158

169
name = "vpc"
1710
application = "clouddrove"
1811
environment = "test"
19-
label_order = ["environment", "name", "application"]
12+
label_order = ["environment", "application", "name"]
2013

2114
cidr_block = "172.16.0.0/16"
2215
}
2316

2417
module "public_subnets" {
25-
source = "git::https://github.com/clouddrove/terraform-aws-subnet.git?ref=tags/0.12.3"
18+
source = "git::https://github.com/clouddrove/terraform-aws-subnet.git?ref=tags/0.12.4"
2619

2720
name = "public-subnet"
2821
application = "clouddrove"
2922
environment = "test"
30-
label_order = ["environment", "name", "application"]
23+
label_order = ["environment", "application", "name"]
3124

32-
availability_zones = ["eu-west-1a", "eu-west-1c"]
25+
availability_zones = ["eu-west-1b", "eu-west-1c"]
3326
vpc_id = module.vpc.vpc_id
3427
cidr_block = module.vpc.vpc_cidr_block
3528
type = "public"
3629
igw_id = module.vpc.igw_id
3730
}
3831

3932
module "http-https" {
40-
source = "git::https://github.com/clouddrove/terraform-aws-security-group.git?ref=tags/0.12.2"
33+
source = "git::https://github.com/clouddrove/terraform-aws-security-group.git?ref=tags/0.12.3"
34+
4135
name = "http-https"
4236
application = "clouddrove"
43-
label_order = ["environment", "name", "application"]
37+
environment = "test"
38+
label_order = ["environment", "application", "name"]
4439

45-
environment = "test"
4640
vpc_id = module.vpc.vpc_id
4741
allowed_ip = ["0.0.0.0/0"]
4842
allowed_ports = [80, 443]
4943
}
5044

5145
module "ssh" {
52-
source = "git::https://github.com/clouddrove/terraform-aws-security-group.git?ref=tags/0.12.2"
46+
source = "git::https://github.com/clouddrove/terraform-aws-security-group.git?ref=tags/0.12.3"
47+
5348
name = "ssh"
5449
application = "clouddrove"
55-
label_order = ["environment", "name", "application"]
50+
environment = "test"
51+
label_order = ["environment", "application", "name"]
5652

57-
environment = "test"
5853
vpc_id = module.vpc.vpc_id
5954
allowed_ip = [module.vpc.vpc_cidr_block]
6055
allowed_ports = [22]
6156
}
6257

58+
module "iam-role" {
59+
source = "git::https://github.com/clouddrove/terraform-aws-iam-role.git?ref=tags/0.12.1"
60+
61+
name = "iam-role"
62+
application = "clouddrove"
63+
environment = "test"
64+
label_order = ["environment", "application", "name"]
65+
assume_role_policy = data.aws_iam_policy_document.default.json
66+
67+
policy_enabled = true
68+
policy = data.aws_iam_policy_document.iam-policy.json
69+
}
70+
71+
data "aws_iam_policy_document" "default" {
72+
statement {
73+
effect = "Allow"
74+
actions = ["sts:AssumeRole"]
75+
principals {
76+
type = "Service"
77+
identifiers = ["ec2.amazonaws.com"]
78+
}
79+
}
80+
}
81+
82+
data "aws_iam_policy_document" "iam-policy" {
83+
statement {
84+
actions = [
85+
"ssm:UpdateInstanceInformation",
86+
"ssmmessages:CreateControlChannel",
87+
"ssmmessages:CreateDataChannel",
88+
"ssmmessages:OpenControlChannel",
89+
"ssmmessages:OpenDataChannel"]
90+
effect = "Allow"
91+
resources = ["*"]
92+
}
93+
}
94+
6395
module "ec2" {
64-
source = "git::https://github.com/clouddrove/terraform-aws-ec2.git?ref=tags/0.12.3"
96+
source = "git::https://github.com/clouddrove/terraform-aws-ec2.git?ref=tags/0.12.4"
6597

6698
name = "ec2-instance"
6799
application = "clouddrove"
68100
environment = "test"
69-
label_order = ["environment", "name", "application"]
70-
71-
instance_count = 2
72-
ami = "ami-08d658f84a6d84a80"
73-
ebs_optimized = false
74-
instance_type = "t2.nano"
75-
key_name = module.keypair.name
76-
monitoring = false
77-
associate_public_ip_address = true
78-
tenancy = "default"
79-
disk_size = 8
101+
label_order = ["environment", "application", "name"]
102+
103+
instance_count = 2
104+
ami = "ami-08d658f84a6d84a80"
105+
instance_type = "t2.nano"
106+
monitoring = false
107+
tenancy = "default"
108+
80109
vpc_security_group_ids_list = [module.ssh.security_group_ids, module.http-https.security_group_ids]
81110
subnet_ids = tolist(module.public_subnets.public_subnet_id)
82111

83-
assign_eip_address = true
112+
assign_eip_address = true
113+
associate_public_ip_address = true
114+
115+
instance_profile_enabled = true
116+
iam_instance_profile = module.iam-role.name
84117

118+
disk_size = 8
119+
ebs_optimized = false
85120
ebs_volume_enabled = true
86121
ebs_volume_type = "gp2"
87122
ebs_volume_size = 30
88123
}
89124

90-
module "acm" {
91-
source = "git::https://github.com/clouddrove/terraform-aws-acm.git?ref=tags/0.12.0"
92-
93-
name = "certificate"
94-
application = "clouddrove"
95-
environment = "test"
96-
label_order = ["environment", "name", "application"]
97-
98-
domain_name = "clouddrove.com"
99-
validation_method = "EMAIL"
100-
validate_certificate = true
101-
}
102125

103126
module "alb" {
104-
source = "git::https://github.com/clouddrove/terraform-aws-alb.git?ref=tags/0.12.2"
127+
source = "./../"
105128

106129
name = "alb"
107130
application = "clouddrove"
108131
environment = "test"
109-
label_order = ["environment", "name", "application"]
132+
label_order = ["environment", "application", "name"]
110133

111134
internal = false
112135
load_balancer_type = "application"
@@ -120,10 +143,9 @@ module "alb" {
120143
target_group_protocol = "HTTP"
121144
target_group_port = 80
122145

123-
listener_certificate_arn = module.acm.arn
124-
https_enabled = true
125-
http_enabled = true
126-
https_port = 443
127-
listener_type = "forward"
146+
https_enabled = false
147+
http_enabled = true
148+
https_port = 443
149+
listener_type = "forward"
128150

129151
}

_test/alb_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ func Test(t *testing.T) {
2929
Tags := terraform.OutputMap(t, terraformOptions, "tags")
3030

3131
// Check that we get back the outputs that we expect
32-
assert.Equal(t, "test-alb-clouddrove", Tags["Name"])
32+
assert.Equal(t, "test-clouddrove-alb", Tags["Name"])
3333
assert.Contains(t, Arn, "arn:aws:elasticloadbalancing")
3434
}

0 commit comments

Comments
 (0)