|
| 1 | +# Attribute validations for account sub module |
| 2 | +run "account_parentId_match" { |
| 3 | + command = plan |
| 4 | + |
| 5 | + variables { |
| 6 | + name = "some_user_name" |
| 7 | + email = "randomPrefix@randomDomain.com" |
| 8 | + parent_id = "ou-rndm-parentid" |
| 9 | + expected_parent_id = "ou-rndm-parentid" |
| 10 | + } |
| 11 | + |
| 12 | + module { |
| 13 | + source = "./modules/account/" |
| 14 | + } |
| 15 | + |
| 16 | + assert { |
| 17 | + condition = aws_organizations_account.member_account.parent_id == var.expected_parent_id |
| 18 | + error_message = "Account parent_id mismatch after creation" |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +run "account_name_match" { |
| 23 | + command = plan |
| 24 | + |
| 25 | + variables { |
| 26 | + name = "some_user_name" |
| 27 | + email = "randomPrefix@randomDomain.com" |
| 28 | + parent_id = "ou-rndm-parentid" |
| 29 | + expected_name = "some_user_name" |
| 30 | + } |
| 31 | + |
| 32 | + module { |
| 33 | + source = "./modules/account/" |
| 34 | + } |
| 35 | + |
| 36 | + assert { |
| 37 | + condition = aws_organizations_account.member_account.name == var.expected_name |
| 38 | + error_message = "Account name mismatch after creation" |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +run "account_email_match" { |
| 43 | + command = plan |
| 44 | + |
| 45 | + variables { |
| 46 | + name = "some_user_name" |
| 47 | + email = "randomPrefix@randomDomain.com" |
| 48 | + parent_id = "ou-rndm-parentid" |
| 49 | + expected_email = "randomPrefix@randomDomain.com" |
| 50 | + } |
| 51 | + |
| 52 | + module { |
| 53 | + source = "./modules/account/" |
| 54 | + } |
| 55 | + |
| 56 | + assert { |
| 57 | + condition = aws_organizations_account.member_account.email == var.expected_email |
| 58 | + error_message = "Account email mismatch after creation" |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +run "account_iam_user_billing_access_enabled" { |
| 63 | + command = plan |
| 64 | + |
| 65 | + module { |
| 66 | + source = "./modules/account/" |
| 67 | + } |
| 68 | + |
| 69 | + variables { |
| 70 | + name = "test_user" |
| 71 | + email = "randomPrefix@randomDomain.com" |
| 72 | + parent_id = "ou-rndm-parentid" |
| 73 | + iam_user_access_to_billing = "ALLOW" |
| 74 | + } |
| 75 | + |
| 76 | + assert { |
| 77 | + condition = aws_organizations_account.member_account.iam_user_access_to_billing == "ALLOW" |
| 78 | + error_message = "IAM user access to billing not enabled as expected" |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +run "account_tags_match" { |
| 83 | + command = plan |
| 84 | + |
| 85 | + module { |
| 86 | + source = "./modules/account/" |
| 87 | + } |
| 88 | + |
| 89 | + variables { |
| 90 | + name = "some_user_name" |
| 91 | + email = "randomPrefix@randomDomain.com" |
| 92 | + parent_id = "ou-rndm-parentid" |
| 93 | + tags = { |
| 94 | + "some_key_name" = "some_value" |
| 95 | + "another_key_name" = "another_value" |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + assert { |
| 100 | + condition = aws_organizations_account.member_account.tags["some_key_name"] == "some_value" |
| 101 | + error_message = "Tag 'some_key_name' with value 'some_value' is missing or incorrect" |
| 102 | + } |
| 103 | + |
| 104 | + assert { |
| 105 | + condition = aws_organizations_account.member_account.tags["another_key_name"] == "another_value" |
| 106 | + error_message = "Tag 'another_key_name' with value 'another_value' is missing or incorrect" |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +# Attribute validations for organization_unit sub module |
| 111 | +run "organizationalUnit_name_match" { |
| 112 | + command = plan |
| 113 | + |
| 114 | + module { |
| 115 | + source = "./modules/organizational_unit/" |
| 116 | + } |
| 117 | + |
| 118 | + variables { |
| 119 | + name = "some_organizationUnit_name" |
| 120 | + parent_id = "ou-rndm-parentid" |
| 121 | + tags = { |
| 122 | + "some_key_name" = "some_value" |
| 123 | + "another_key_name" = "another_value" |
| 124 | + } |
| 125 | + expected_name = "some_organizationUnit_name" |
| 126 | + } |
| 127 | + |
| 128 | + assert { |
| 129 | + condition = aws_organizations_organizational_unit.org_unit.name == var.expected_name |
| 130 | + error_message = "Organization unit name mismatch after creation" |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +run "organizationalUnit_parentId_match" { |
| 135 | + command = plan |
| 136 | + |
| 137 | + module { |
| 138 | + source = "./modules/organizational_unit/" |
| 139 | + } |
| 140 | + |
| 141 | + variables { |
| 142 | + name = "some_organizationUnit_name" |
| 143 | + parent_id = "ou-rndm-parentid" |
| 144 | + tags = { |
| 145 | + "some_key_name" = "some_value" |
| 146 | + "another_key_name" = "another_value" |
| 147 | + } |
| 148 | + expected_parent_id = "ou-rndm-parentid" |
| 149 | + } |
| 150 | + |
| 151 | + assert { |
| 152 | + condition = aws_organizations_organizational_unit.org_unit.parent_id == var.expected_parent_id |
| 153 | + error_message = "Organization unit name mismatch after creation" |
| 154 | + } |
| 155 | +} |
| 156 | + |
| 157 | +run "organizationalUnit_tags_match" { |
| 158 | + command = plan |
| 159 | + |
| 160 | + module { |
| 161 | + source = "./modules/organizational_unit/" |
| 162 | + } |
| 163 | + |
| 164 | + variables { |
| 165 | + name = "some_organizationUnit_name" |
| 166 | + parent_id = "ou-rndm-parentid" |
| 167 | + tags = { |
| 168 | + "some_key_name" = "some_value" |
| 169 | + "another_key_name" = "another_value" |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + assert { |
| 174 | + condition = aws_organizations_organizational_unit.org_unit.tags["some_key_name"] == "some_value" |
| 175 | + error_message = "Tag 'some_key_name' with value 'some_value' is missing or incorrect" |
| 176 | + } |
| 177 | + assert { |
| 178 | + condition = aws_organizations_organizational_unit.org_unit.tags["another_key_name"] == "another_value" |
| 179 | + error_message = "Tag 'another_key_name' with value 'another_value' is missing or incorrect" |
| 180 | + } |
| 181 | +} |
| 182 | + |
| 183 | +# Attribute validations for organization module |
| 184 | +run "organization_aws_service_access_principals_match" { |
| 185 | + command = plan |
| 186 | + |
| 187 | + variables { |
| 188 | + service_access_principals = ["service1.amazonaws.com", "service2.amazonaws.com"] |
| 189 | + expected_aws_service_access_principals = ["service1.amazonaws.com", "service2.amazonaws.com"] |
| 190 | + enabled_policy_types = ["SERVICE_CONTROL_POLICY"] |
| 191 | + feature_set = "ALL" |
| 192 | + } |
| 193 | + |
| 194 | + module { |
| 195 | + source = "./" |
| 196 | + } |
| 197 | + |
| 198 | + assert { |
| 199 | + condition = toset(aws_organizations_organization.org.aws_service_access_principals) == toset(var.expected_aws_service_access_principals) |
| 200 | + error_message = "AWS service access principals mismatch after creation" |
| 201 | + } |
| 202 | +} |
| 203 | + |
| 204 | +run "organization_enabled_policy_types_match" { |
| 205 | + command = plan |
| 206 | + |
| 207 | + variables { |
| 208 | + service_access_principals = ["service1.amazonaws.com", "service2.amazonaws.com"] |
| 209 | + enabled_policy_types = ["SERVICE_CONTROL_POLICY"] |
| 210 | + expected_enabled_policy_types = ["SERVICE_CONTROL_POLICY"] |
| 211 | + feature_set = "ALL" |
| 212 | + } |
| 213 | + |
| 214 | + module { |
| 215 | + source = "./" |
| 216 | + } |
| 217 | + |
| 218 | + assert { |
| 219 | + condition = toset(aws_organizations_organization.org.enabled_policy_types) == toset(var.expected_enabled_policy_types) |
| 220 | + error_message = "Enabled policy types mismatch after creation" |
| 221 | + } |
| 222 | +} |
| 223 | + |
| 224 | +run "organization_feature_set_match" { |
| 225 | + command = plan |
| 226 | + |
| 227 | + variables { |
| 228 | + service_access_principals = ["service1.amazonaws.com", "service2.amazonaws.com"] |
| 229 | + enabled_policy_types = ["SERVICE_CONTROL_POLICY"] |
| 230 | + feature_set = "ALL" |
| 231 | + expected_feature_set = "ALL" |
| 232 | + } |
| 233 | + |
| 234 | + module { |
| 235 | + source = "./" |
| 236 | + } |
| 237 | + |
| 238 | + assert { |
| 239 | + condition = aws_organizations_organization.org.feature_set == var.expected_feature_set |
| 240 | + error_message = "Feature set mismatch after creation" |
| 241 | + } |
| 242 | +} |
0 commit comments