11
2- /*
3- | -- #### ######################## ####
4- | -- #### AWS Cloud Authentication ####
5- | -- #### ######################## ####
6- | --
7- | -- This role arn prompts terraform to assume the role specified. Now
8- | -- credentials will be sought from the environment when running within
9- | -- local surrounds like (on a laptop), however when on an EC2 server
10- | -- or within an ECS cluster the environment already has the role.
11- | --
12- */
13- variable in_role_arn {
14- description = " The Role ARN to use when we assume role to implement the provisioning."
15- }
16-
17- provider aws {
18- assume_role {
19- role_arn = var. in_role_arn
20- }
21- }
22-
23- locals {
24- ecosystem_name = " integration"
25- fresh_db_name = " brandnewbox"
26- clone_db_name = " copycatbox"
27- }
28-
29-
30- variable in_id_of_db_to_clone {
31- description = " The ID of mummy database to clone from."
32- }
2+ # ## ############################ ###
3+ # ## Example RDS Postgres Outputs ###
4+ # ## ############################ ###
335
346output out_fresh_database_hostname { value = module. fresh_db . out_fresh_db_hostname }
357output out_fresh_database_endpoint { value = module. fresh_db . out_fresh_db_endpoint }
@@ -53,8 +25,8 @@ module fresh_db {
5325 in_database_name = local. fresh_db_name
5426
5527 in_ecosystem = local. ecosystem_name
56- in_timestamp = module . resource-tags . out_tag_timestamp
57- in_description = module . resource-tags . out_tag_description
28+ in_timestamp = local . timestamp
29+ in_description = local . description
5830}
5931
6032
@@ -70,21 +42,23 @@ module clone_db {
7042 in_database_name = local. clone_db_name
7143
7244 in_ecosystem = local. ecosystem_name
73- in_timestamp = module . resource-tags . out_tag_timestamp
74- in_description = module . resource-tags . out_tag_description
45+ in_timestamp = local . timestamp
46+ in_description = local . description
7547}
7648
7749
7850module vpc-network {
7951
80- source = " github.com/devops4me/terraform-aws-vpc-network"
52+ source = " devops4me/vpc-network/aws"
53+ version = " 1.0.2"
54+
8155 in_vpc_cidr = " 10.81.0.0/16"
8256 in_num_public_subnets = 3
8357 in_num_private_subnets = 3
8458
8559 in_ecosystem = local. ecosystem_name
86- in_timestamp = module . resource-tags . out_tag_timestamp
87- in_description = module . resource-tags . out_tag_description
60+ in_timestamp = local . timestamp
61+ in_description = local . description
8862}
8963
9064
@@ -94,14 +68,67 @@ module security-group {
9468 in_ingress = [ " postgres" ]
9569 in_vpc_id = module. vpc-network . out_vpc_id
9670
97- in_ecosystem = local. ecosystem_name
98- in_timestamp = module . resource-tags . out_tag_timestamp
99- in_description = module . resource-tags . out_tag_description
71+ in_ecosystem_name = local. ecosystem_name
72+ in_tag_timestamp = local . timestamp
73+ in_tag_description = local . description
10074}
10175
10276
103- module resource-tags {
77+ locals {
78+ fresh_db_name = " brandnewdb"
79+ clone_db_name = " snapshotdb"
80+ }
10481
105- source = " github.com/devops4me/terraform-aws-resource-tags"
10682
83+ variable in_id_of_db_to_clone {
84+ description = " The ID of mummy database to clone from."
85+ }
86+
87+
88+
89+ /*
90+ | --
91+ | -- If you are using an IAM role as the AWS access mechanism then
92+ | -- pass it as in_role_arn commonly through an environment variable
93+ | -- named TF_VAR_in_role_arn in addition to the usual AWS access
94+ | -- key, secret key and default region parameters.
95+ | --
96+ | -- Individuals and small businesses without hundreds of AWS accounts
97+ | -- can omit the in_role_arn variable. and thanks to dynamic assignment
98+ | --
99+ */
100+ provider aws {
101+ dynamic assume_role {
102+ for_each = length ( var. in_role_arn ) > 0 ? [ var . in_role_arn ] : []
103+ content {
104+ role_arn = assume_role. value
105+ }
106+ }
107+ }
108+
109+ variable in_role_arn {
110+ description = " The Role ARN to use when we assume role to implement the provisioning."
111+ default = " "
112+ }
113+
114+
115+ /*
116+ | --
117+ | -- ### ############# ###
118+ | -- ### Resource Tags ###
119+ | -- ### ############# ###
120+ | --
121+ | -- Terraform will tag every significant resource allowing you to report and collate
122+ | --
123+ | -- [1] - all infrastructure in all environments dedicated to your app (ecosystem_name)
124+ | -- [2] - the infrastructure dedicated to this environment instance (timestamp)
125+ | --
126+ | -- The human readable description reveals the when, where and what of the infrastructure.
127+ | --
128+ */
129+ locals {
130+ ecosystem_name = " dbstack"
131+ timestamp = formatdate ( " YYMMDDhhmmss" , timestamp () )
132+ date_time = formatdate ( " EEEE DD-MMM-YY hh:mm:ss ZZZ" , timestamp () )
133+ description = " was created by me on ${ local . date_time } ."
107134}
0 commit comments