|
1 | 1 |
|
2 |
| -locals |
3 |
| -{ |
4 |
| - ecosystem_name = "sec-group-test" |
| 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 = "security-grp-ex" |
| 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 }." |
5 | 33 | }
|
6 | 34 |
|
7 |
| -module virtual-private-cloud-1 |
8 |
| -{ |
9 |
| - source = "github.com/devops4me/terraform-aws-vpc-network" |
| 35 | + |
| 36 | +### ############################## ### |
| 37 | +### Example Security Group Modules ### |
| 38 | +### ############################## ### |
| 39 | + |
| 40 | +module virtual-private-cloud-1 { |
| 41 | + |
| 42 | + source = "devops4me/vpc-network/aws" |
| 43 | + version = "~> 1.0.3" |
| 44 | + |
10 | 45 | in_vpc_cidr = "10.123.0.0/16"
|
11 | 46 | in_create_private_gateway = false
|
12 | 47 | in_create_public_gateway = false
|
13 | 48 |
|
14 |
| - in_ecosystem_name = "${ local.ecosystem_name }-01" |
15 |
| - in_tag_timestamp = "${ module.resource-tags.out_tag_timestamp }" |
16 |
| - in_tag_description = "${ module.resource-tags.out_tag_description }" |
| 49 | + in_ecosystem = "${ local.ecosystem_name }-01" |
| 50 | + in_timestamp = local.timestamp |
| 51 | + in_description = local.description |
17 | 52 | }
|
18 | 53 |
|
19 |
| -module security-group-test-1a |
20 |
| -{ |
21 |
| - source = ".." |
22 |
| - in_vpc_id = "${ module.virtual-private-cloud-1.out_vpc_id }" |
23 |
| - in_ingress = [ "elastic", "java" ] |
| 54 | +module security-group-test-1a { |
24 | 55 |
|
25 |
| - in_ecosystem_name = "${ local.ecosystem_name }-1a" |
26 |
| - in_tag_timestamp = "${ module.resource-tags.out_tag_timestamp }" |
27 |
| - in_tag_description = "${ module.resource-tags.out_tag_description }" |
| 56 | + source = "./.." |
| 57 | + in_vpc_id = module.virtual-private-cloud-1.out_vpc_id |
| 58 | + in_ingress = [ "docker", "java" ] |
| 59 | + |
| 60 | + in_ecosystem = "${ local.ecosystem_name }-1a" |
| 61 | + in_timestamp = local.timestamp |
| 62 | + in_description = local.description |
28 | 63 | }
|
29 | 64 |
|
30 |
| -module security-group-test-1b |
31 |
| -{ |
32 |
| - source = ".." |
33 |
| - in_vpc_id = "${ module.virtual-private-cloud-1.out_vpc_id }" |
| 65 | +module security-group-test-1b { |
| 66 | + |
| 67 | + source = "./.." |
| 68 | + in_vpc_id = module.virtual-private-cloud-1.out_vpc_id |
34 | 69 | in_ingress = [ "ssh", "http", "https" ]
|
35 | 70 |
|
36 |
| - in_ecosystem_name = "${ local.ecosystem_name }-1b" |
37 |
| - in_tag_timestamp = "${ module.resource-tags.out_tag_timestamp }" |
38 |
| - in_tag_description = "${ module.resource-tags.out_tag_description }" |
| 71 | + in_ecosystem = "${ local.ecosystem_name }-1b" |
| 72 | + in_timestamp = local.timestamp |
| 73 | + in_description = local.description |
39 | 74 | }
|
40 | 75 |
|
41 |
| -module virtual-private-cloud-2 |
42 |
| -{ |
43 |
| - source = "github.com/devops4me/terraform-aws-vpc-network" |
| 76 | +module virtual-private-cloud-2 { |
| 77 | + |
| 78 | + source = "devops4me/vpc-network/aws" |
| 79 | + version = "~> 1.0.3" |
| 80 | + |
44 | 81 | in_vpc_cidr = "10.124.0.0/16"
|
45 | 82 | in_create_private_gateway = false
|
46 | 83 | in_create_public_gateway = false
|
47 | 84 |
|
48 |
| - in_ecosystem_name = "${ local.ecosystem_name }-02" |
49 |
| - in_tag_timestamp = "${ module.resource-tags.out_tag_timestamp }" |
50 |
| - in_tag_description = "${ module.resource-tags.out_tag_description }" |
| 85 | + in_ecosystem = "${ local.ecosystem_name }-02" |
| 86 | + in_timestamp = local.timestamp |
| 87 | + in_description = local.description |
51 | 88 | }
|
52 | 89 |
|
53 |
| -module security-group-test-2a |
54 |
| -{ |
55 |
| - source = ".." |
56 |
| - in_ingress = [ "elastic", "ssh", "java" ] |
| 90 | +module security-group-test-2a { |
| 91 | + |
| 92 | + source = "./.." |
| 93 | + in_ingress = [ "https", "ssh", "jenkins" ] |
57 | 94 | in_egress = [ "all-traffic" ]
|
58 |
| - in_vpc_id = "${ module.virtual-private-cloud-2.out_vpc_id }" |
| 95 | + in_vpc_id = module.virtual-private-cloud-2.out_vpc_id |
59 | 96 |
|
60 |
| - in_ecosystem_name = "${ local.ecosystem_name }-2a" |
61 |
| - in_tag_timestamp = "${ module.resource-tags.out_tag_timestamp }" |
62 |
| - in_tag_description = "${ module.resource-tags.out_tag_description }" |
| 97 | + in_ecosystem = "${ local.ecosystem_name }-2a" |
| 98 | + in_timestamp = local.timestamp |
| 99 | + in_description = local.description |
63 | 100 | }
|
64 | 101 |
|
65 |
| -module security-group-test-2b |
66 |
| -{ |
67 |
| - source = "github.com/devops4me/terraform-aws-security-group" |
68 |
| - in_vpc_id = "${ module.virtual-private-cloud-2.out_vpc_id }" |
69 |
| - in_ingress = [ "etcd-client", "etcd-server", "epmd" ] |
70 |
| - |
71 |
| - in_ecosystem_name = "${ local.ecosystem_name }-2b" |
72 |
| - in_tag_timestamp = "${ module.resource-tags.out_tag_timestamp }" |
73 |
| - in_tag_description = "${ module.resource-tags.out_tag_description }" |
74 |
| -} |
| 102 | +module security-group-test-2b { |
75 | 103 |
|
76 |
| -/* |
77 |
| - | -- |
78 |
| - | -- Remember the AWS resource tags! Using this module, every |
79 |
| - | -- infrastructure component is tagged to tell you 5 things. |
80 |
| - | -- |
81 |
| - | -- a) who (which IAM user) created the component |
82 |
| - | -- b) which eco-system instance is this component a part of |
83 |
| - | -- c) when (timestamp) was this component created |
84 |
| - | -- d) where (in which AWS region) was this component created |
85 |
| - | -- e) which eco-system class is this component a part of |
86 |
| - | -- |
87 |
| -*/ |
88 |
| -module resource-tags |
89 |
| -{ |
90 |
| - source = "github.com/devops4me/terraform-aws-resource-tags" |
91 |
| -} |
92 |
| - |
93 |
| -output security_group_id_1a |
94 |
| -{ |
95 |
| - value = "${module.security-group-test-1a.out_security_group_id}" |
96 |
| -} |
| 104 | + source = "./.." |
| 105 | + in_vpc_id = module.virtual-private-cloud-2.out_vpc_id |
| 106 | + in_ingress = [ "sonar", "postgres", "ecs" ] |
97 | 107 |
|
98 |
| -output security_group_id_2b |
99 |
| -{ |
100 |
| - value = "${module.security-group-test-2b.out_security_group_id}" |
| 108 | + in_ecosystem = "${ local.ecosystem_name }-2b" |
| 109 | + in_timestamp = local.timestamp |
| 110 | + in_description = local.description |
101 | 111 | }
|
0 commit comments