1
1
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
+ # ## ############################ ###
33
5
34
6
output out_fresh_database_hostname { value = module. fresh_db . out_fresh_db_hostname }
35
7
output out_fresh_database_endpoint { value = module. fresh_db . out_fresh_db_endpoint }
@@ -53,8 +25,8 @@ module fresh_db {
53
25
in_database_name = local. fresh_db_name
54
26
55
27
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
58
30
}
59
31
60
32
@@ -70,21 +42,23 @@ module clone_db {
70
42
in_database_name = local. clone_db_name
71
43
72
44
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
75
47
}
76
48
77
49
78
50
module vpc-network {
79
51
80
- source = " github.com/devops4me/terraform-aws-vpc-network"
52
+ source = " devops4me/vpc-network/aws"
53
+ version = " 1.0.2"
54
+
81
55
in_vpc_cidr = " 10.81.0.0/16"
82
56
in_num_public_subnets = 3
83
57
in_num_private_subnets = 3
84
58
85
59
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
88
62
}
89
63
90
64
@@ -94,14 +68,67 @@ module security-group {
94
68
in_ingress = [ " postgres" ]
95
69
in_vpc_id = module. vpc-network . out_vpc_id
96
70
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
100
74
}
101
75
102
76
103
- module resource-tags {
77
+ locals {
78
+ fresh_db_name = " brandnewdb"
79
+ clone_db_name = " snapshotdb"
80
+ }
104
81
105
- source = " github.com/devops4me/terraform-aws-resource-tags"
106
82
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 } ."
107
134
}
0 commit comments