|
| 1 | +provider "aws" { |
| 2 | + region = "ap-south-1" |
| 3 | +} |
| 4 | + |
| 5 | +################################################################################ |
| 6 | +# DB Instance |
| 7 | +################################################################################ |
| 8 | + |
| 9 | +run "db_instance_attributes_match" { |
| 10 | + command = plan |
| 11 | + |
| 12 | + module { |
| 13 | + source = "./modules/rds" |
| 14 | + } |
| 15 | + |
| 16 | + variables { |
| 17 | + identifier = "example-identifier" |
| 18 | + instance_class = "example-instance-class" |
| 19 | + allocated_storage = 1234 |
| 20 | + engine = "example-engine" |
| 21 | + engine_version = "example-engine-version" |
| 22 | + vpc_security_group_ids = ["sg-1234567890abcdef"] |
| 23 | + db_name = "example-db-name" |
| 24 | + username = "example-username" |
| 25 | + skip_final_snapshot = true |
| 26 | + |
| 27 | + db_subnet_group_name = "example-db-subnet-group-name" |
| 28 | + db_subnet_group_subnet_ids = ["subnet-1234567890abcdef"] |
| 29 | + |
| 30 | + db_parameter_group_name = "example-db-parameter-group-name" |
| 31 | + db_parameter_group_family = "example-db-parameter-group-family" |
| 32 | + |
| 33 | + tags = { |
| 34 | + Example = "Tag" |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + assert { |
| 39 | + condition = aws_db_instance.this.identifier == var.identifier |
| 40 | + error_message = "Identifier mismatch" |
| 41 | + } |
| 42 | + |
| 43 | + assert { |
| 44 | + condition = aws_db_instance.this.instance_class == var.instance_class |
| 45 | + error_message = "Instance class mismatch" |
| 46 | + } |
| 47 | + |
| 48 | + assert { |
| 49 | + condition = aws_db_instance.this.storage_type == var.storage_type |
| 50 | + error_message = "Storage type mismatch" |
| 51 | + } |
| 52 | + |
| 53 | + assert { |
| 54 | + condition = aws_db_instance.this.allocated_storage == var.allocated_storage |
| 55 | + error_message = "Allocated storage mismatch" |
| 56 | + } |
| 57 | + |
| 58 | + assert { |
| 59 | + condition = aws_db_instance.this.engine == var.engine |
| 60 | + error_message = "Engine mismatch" |
| 61 | + } |
| 62 | + |
| 63 | + assert { |
| 64 | + condition = aws_db_instance.this.engine_version == var.engine_version |
| 65 | + error_message = "Engine version mismatch" |
| 66 | + } |
| 67 | + |
| 68 | + assert { |
| 69 | + condition = aws_db_instance.this.vpc_security_group_ids == toset(var.vpc_security_group_ids) |
| 70 | + error_message = "VPC security group ids mismatch" |
| 71 | + } |
| 72 | + |
| 73 | + assert { |
| 74 | + condition = aws_db_instance.this.db_subnet_group_name == var.db_subnet_group_name |
| 75 | + error_message = "Db subnet group name mismatch" |
| 76 | + } |
| 77 | + |
| 78 | + assert { |
| 79 | + condition = aws_db_instance.this.parameter_group_name == var.db_parameter_group_name |
| 80 | + error_message = "Db parameter group name mismatch" |
| 81 | + } |
| 82 | + |
| 83 | + assert { |
| 84 | + condition = aws_db_instance.this.db_name == var.db_name |
| 85 | + error_message = "Db name mismatch" |
| 86 | + } |
| 87 | + |
| 88 | + assert { |
| 89 | + condition = aws_db_instance.this.username == var.username |
| 90 | + error_message = "Username mismatch" |
| 91 | + } |
| 92 | + |
| 93 | + assert { |
| 94 | + condition = aws_db_instance.this.manage_master_user_password == true |
| 95 | + error_message = "Manage master user password mismatch" |
| 96 | + } |
| 97 | + |
| 98 | + assert { |
| 99 | + condition = aws_db_instance.this.skip_final_snapshot == var.skip_final_snapshot |
| 100 | + error_message = "Skip final snapshot mismatch" |
| 101 | + } |
| 102 | + |
| 103 | + assert { |
| 104 | + condition = aws_db_instance.this.tags == var.tags |
| 105 | + error_message = "Tags mismatch" |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +################################################################################ |
| 110 | +# DB Subnet Group |
| 111 | +################################################################################ |
| 112 | + |
| 113 | +run "db_subnet_group_attributes_match" { |
| 114 | + command = plan |
| 115 | + |
| 116 | + module { |
| 117 | + source = "./modules/rds" |
| 118 | + } |
| 119 | + |
| 120 | + variables { |
| 121 | + identifier = "example-identifier" |
| 122 | + instance_class = "example-instance-class" |
| 123 | + allocated_storage = 1234 |
| 124 | + engine = "example-engine" |
| 125 | + engine_version = "example-engine-version" |
| 126 | + vpc_security_group_ids = ["sg-1234567890abcdef"] |
| 127 | + db_name = "example-db-name" |
| 128 | + username = "example-username" |
| 129 | + skip_final_snapshot = null |
| 130 | + |
| 131 | + db_subnet_group_name = "example-db-subnet-group-name" |
| 132 | + db_subnet_group_description = "example-db-subnet-group-description" |
| 133 | + db_subnet_group_subnet_ids = ["subnet-1234567890abcdef"] |
| 134 | + db_subnet_group_tags = { |
| 135 | + ExampleDb = "SubnetGroupTag" |
| 136 | + } |
| 137 | + |
| 138 | + db_parameter_group_name = "example-db-parameter-group-name" |
| 139 | + db_parameter_group_family = "example-db-parameter-group-family" |
| 140 | + } |
| 141 | + |
| 142 | + assert { |
| 143 | + condition = aws_db_subnet_group.this.name == var.db_subnet_group_name |
| 144 | + error_message = "Name mismatch" |
| 145 | + } |
| 146 | + |
| 147 | + assert { |
| 148 | + condition = aws_db_subnet_group.this.description == var.db_subnet_group_description |
| 149 | + error_message = "Description mismatch" |
| 150 | + } |
| 151 | + |
| 152 | + assert { |
| 153 | + condition = aws_db_subnet_group.this.subnet_ids == toset(var.db_subnet_group_subnet_ids) |
| 154 | + error_message = "Subnet ids mismatch" |
| 155 | + } |
| 156 | + |
| 157 | + assert { |
| 158 | + condition = aws_db_subnet_group.this.tags == var.db_subnet_group_tags |
| 159 | + error_message = "Tags mismatch" |
| 160 | + } |
| 161 | +} |
| 162 | + |
| 163 | +################################################################################ |
| 164 | +# DB Parameter Group |
| 165 | +################################################################################ |
| 166 | + |
| 167 | +run "db_parameter_group_attributes_match" { |
| 168 | + command = plan |
| 169 | + |
| 170 | + module { |
| 171 | + source = "./modules/rds" |
| 172 | + } |
| 173 | + |
| 174 | + variables { |
| 175 | + identifier = "example-identifier" |
| 176 | + instance_class = "example-instance-class" |
| 177 | + allocated_storage = 1234 |
| 178 | + engine = "example-engine" |
| 179 | + engine_version = "example-engine-version" |
| 180 | + vpc_security_group_ids = ["sg-1234567890abcdef"] |
| 181 | + db_name = "example-db-name" |
| 182 | + username = "example-username" |
| 183 | + skip_final_snapshot = null |
| 184 | + |
| 185 | + db_subnet_group_name = "example-db-subnet-group-name" |
| 186 | + db_subnet_group_subnet_ids = ["subnet-1234567890abcdef"] |
| 187 | + |
| 188 | + db_parameter_group_name = "example-db-parameter-group-name" |
| 189 | + db_parameter_group_description = "example-db-parameter-group-description" |
| 190 | + db_parameter_group_family = "example-db-parameter-group-family" |
| 191 | + db_parameter_group_parameters = [ |
| 192 | + { |
| 193 | + name = "example-param" |
| 194 | + value = "example-param-value" |
| 195 | + apply_method = "pending-reboot" |
| 196 | + } |
| 197 | + ] |
| 198 | + db_parameter_group_tags = { |
| 199 | + ExampleDb = "ParameterGroupTag" |
| 200 | + } |
| 201 | + } |
| 202 | + |
| 203 | + assert { |
| 204 | + condition = aws_db_parameter_group.this.name == var.db_parameter_group_name |
| 205 | + error_message = "Name mismatch" |
| 206 | + } |
| 207 | + |
| 208 | + assert { |
| 209 | + condition = aws_db_parameter_group.this.description == var.db_parameter_group_description |
| 210 | + error_message = "Description mismatch" |
| 211 | + } |
| 212 | + |
| 213 | + assert { |
| 214 | + condition = aws_db_parameter_group.this.family == var.db_parameter_group_family |
| 215 | + error_message = "Family mismatch" |
| 216 | + } |
| 217 | + |
| 218 | + assert { |
| 219 | + condition = length(aws_db_parameter_group.this.parameter) == 1 |
| 220 | + error_message = "Parameter count mismatch" |
| 221 | + } |
| 222 | + |
| 223 | + assert { |
| 224 | + condition = tolist(aws_db_parameter_group.this.parameter)[0] == var.db_parameter_group_parameters[0] |
| 225 | + error_message = "Parameter mismatch" |
| 226 | + } |
| 227 | + |
| 228 | + assert { |
| 229 | + condition = aws_db_parameter_group.this.tags == var.db_parameter_group_tags |
| 230 | + error_message = "Tags mismatch" |
| 231 | + } |
| 232 | +} |
0 commit comments