Skip to content

Commit 8573649

Browse files
committed
example has been split into variables outputs and main and refactored
1 parent 264aec6 commit 8573649

File tree

4 files changed

+89
-122
lines changed

4 files changed

+89
-122
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,39 @@
11

2+
/*
3+
| --
4+
| -- If you are using an IAM role as the AWS access mechanism then
5+
| -- pass it as in_role_arn commonly through an environment variable
6+
| -- named TF_VAR_in_role_arn in addition to the usual AWS access
7+
| -- key, secret key and default region parameters.
8+
| --
9+
*/
10+
provider aws {
11+
dynamic assume_role {
12+
for_each = length( var.in_role_arn ) > 0 ? [ var.in_role_arn ] : []
13+
content {
14+
role_arn = assume_role.value
15+
}
16+
}
17+
}
18+
19+
20+
/*
21+
| --
22+
| -- Terraform will tag every significant resource allowing you to report and collate
23+
| --
24+
| -- [1] - all infrastructure in all environments dedicated to your app (ecosystem_name)
25+
| -- [2] - the infrastructure dedicated to this environment instance (timestamp)
26+
| --
27+
*/
28+
locals {
29+
ecosystem_name = "virtual-net"
30+
timestamp = formatdate( "YYMMDDhhmmss", timestamp() )
31+
date_time = formatdate( "EEEE DD-MMM-YY hh:mm:ss ZZZ", timestamp() )
32+
description = "was created by me on ${ local.date_time }."
33+
}
34+
35+
36+
237
### #################### ###
338
### Example VPC Networks ###
439
### #################### ###
@@ -40,68 +75,3 @@ module no-private-subnets {
4075
in_timestamp = local.timestamp
4176
in_description = local.description
4277
}
43-
44-
45-
### ########################### ###
46-
### Example VPC Network Outputs ###
47-
### ########################### ###
48-
49-
output subnet_ids_1{ value = module.vpc-net.out_subnet_ids }
50-
output private_subnet_ids_1{ value = module.vpc-net.out_private_subnet_ids }
51-
output public_subnet_ids_1{ value = module.vpc-net.out_public_subnet_ids }
52-
53-
output subnet_ids_2{ value = module.two-pub-priv-subnets.out_subnet_ids }
54-
output private_subnet_ids_2{ value = module.two-pub-priv-subnets.out_private_subnet_ids }
55-
output public_subnet_ids_2{ value = module.two-pub-priv-subnets.out_public_subnet_ids }
56-
57-
output subnet_ids_3{ value = module.no-private-subnets.out_subnet_ids }
58-
output private_subnet_ids_3{ value = module.no-private-subnets.out_private_subnet_ids }
59-
output public_subnet_ids_3{ value = module.no-private-subnets.out_public_subnet_ids }
60-
61-
62-
/*
63-
| --
64-
| -- If you are using an IAM role as the AWS access mechanism then
65-
| -- pass it as in_role_arn commonly through an environment variable
66-
| -- named TF_VAR_in_role_arn in addition to the usual AWS access
67-
| -- key, secret key and default region parameters.
68-
| --
69-
| -- Individuals and small businesses without hundreds of AWS accounts
70-
| -- can omit the in_role_arn variable. and thanks to dynamic assignment
71-
| --
72-
*/
73-
provider aws {
74-
dynamic assume_role {
75-
for_each = length( var.in_role_arn ) > 0 ? [ var.in_role_arn ] : []
76-
content {
77-
role_arn = assume_role.value
78-
}
79-
}
80-
}
81-
82-
variable in_role_arn {
83-
description = "The Role ARN to use when we assume role to implement the provisioning."
84-
default = ""
85-
}
86-
87-
88-
/*
89-
| --
90-
| -- ### ############# ###
91-
| -- ### Resource Tags ###
92-
| -- ### ############# ###
93-
| --
94-
| -- Terraform will tag every significant resource allowing you to report and collate
95-
| --
96-
| -- [1] - all infrastructure in all environments dedicated to your app (ecosystem_name)
97-
| -- [2] - the infrastructure dedicated to this environment instance (timestamp)
98-
| --
99-
| -- The human readable description reveals the when, where and what of the infrastructure.
100-
| --
101-
*/
102-
locals {
103-
ecosystem_name = "virtual-net"
104-
timestamp = formatdate( "YYMMDDhhmmss", timestamp() )
105-
date_time = formatdate( "EEEE DD-MMM-YY hh:mm:ss ZZZ", timestamp() )
106-
description = "was created by me on ${ local.date_time }."
107-
}

example/vpc.example-outputs.tf

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
### ########################### ###
3+
### Example VPC Network Outputs ###
4+
### ########################### ###
5+
6+
output subnet_ids_1 {
7+
value = module.vpc-net.out_subnet_ids
8+
}
9+
10+
output private_subnet_ids_1 {
11+
value = module.vpc-net.out_private_subnet_ids
12+
}
13+
14+
output public_subnet_ids_1 {
15+
value = module.vpc-net.out_public_subnet_ids
16+
}
17+
18+
output subnet_ids_2 {
19+
value = module.two-pub-priv-subnets.out_subnet_ids
20+
}
21+
22+
output private_subnet_ids_2 {
23+
value = module.two-pub-priv-subnets.out_private_subnet_ids
24+
}
25+
26+
output public_subnet_ids_2 {
27+
value = module.two-pub-priv-subnets.out_public_subnet_ids
28+
}
29+
30+
output subnet_ids_3 {
31+
value = module.no-private-subnets.out_subnet_ids
32+
}
33+
34+
output private_subnet_ids_3 {
35+
value = module.no-private-subnets.out_private_subnet_ids
36+
}
37+
38+
output public_subnet_ids_3 {
39+
value = module.no-private-subnets.out_public_subnet_ids
40+
}

example/vpc.example-variables.tf

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
/*
3+
| --
4+
| -- If you are using an IAM role as the AWS access mechanism then
5+
| -- pass it as in_role_arn commonly through an environment variable
6+
| -- named TF_VAR_in_role_arn in addition to the usual AWS access
7+
| -- key, secret key and default region parameters.
8+
| --
9+
*/
10+
variable in_role_arn {
11+
description = "The optional role arn to use if your AWS access mechanism is via IAM roles."
12+
default = ""
13+
type = string
14+
}

template_for_flow_logs.txt

-57
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,4 @@
11

22
### Use this template to create flow logs module
33

4-
data "aws_iam_policy_document" "flow_log_role" {
5-
statement {
6-
sid = ""
7-
8-
actions = [
9-
"sts:AssumeRole",
10-
]
11-
12-
principals {
13-
type = "Service"
14-
identifiers = ["vpc-flow-logs.amazonaws.com"]
15-
}
16-
}
17-
}
18-
19-
resource "aws_iam_role" "flow_log_role" {
20-
name = "flow_log_role-${var.environment}"
21-
assume_role_policy = "${data.aws_iam_policy_document.flow_log_role.json}"
22-
}
23-
24-
data "aws_iam_policy_document" "flow_log_policy" {
25-
statement {
26-
actions = [
27-
"logs:CreateLogGroup",
28-
"logs:CreateLogStream",
29-
"logs:PutLogEvents",
30-
"logs:DescribeLogGroups",
31-
"logs:DescribeLogStreams",
32-
]
33-
34-
resources = [
35-
"*",
36-
]
37-
}
38-
}
39-
40-
resource "aws_iam_role_policy" "flow_log_policy" {
41-
name = "flow_log_policy-${var.environment}"
42-
role = "${aws_iam_role.flow_log_role.id}"
43-
policy = "${data.aws_iam_policy_document.flow_log_policy.json}"
44-
}
45-
46-
resource "aws_cloudwatch_log_group" "vpc-flow-log-group" {
47-
name = "vpc-flow-log-group-${var.environment}"
48-
49-
tags = "${merge(
50-
map("Name", "vpc-flow-log-group-${var.environment}"),
51-
var.tags
52-
)}"
53-
}
54-
55-
resource "aws_flow_log" "flow_log" {
56-
log_destination = "${aws_cloudwatch_log_group.vpc-flow-log-group.arn}"
57-
iam_role_arn = "${aws_iam_role.flow_log_role.arn}"
58-
vpc_id = "${aws_vpc.shared-services.id}"
59-
traffic_type = "ALL"
60-
}
614

0 commit comments

Comments
 (0)