11# 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- }
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+ }
2121
2222run "account_name_match" {
2323 command = plan
@@ -185,10 +185,10 @@ run "organization_aws_service_access_principals_match" {
185185 command = plan
186186
187187 variables {
188- service_access_principals = [" service1.amazonaws.com" , " service2.amazonaws.com" ]
188+ service_access_principals = [" service1.amazonaws.com" , " service2.amazonaws.com" ]
189189 expected_aws_service_access_principals = [" service1.amazonaws.com" , " service2.amazonaws.com" ]
190- enabled_policy_types = [" SERVICE_CONTROL_POLICY" ]
191- feature_set = " ALL"
190+ enabled_policy_types = [" SERVICE_CONTROL_POLICY" ]
191+ feature_set = " ALL"
192192 }
193193
194194 module {
@@ -205,10 +205,10 @@ run "organization_enabled_policy_types_match" {
205205 command = plan
206206
207207 variables {
208- service_access_principals = [" service1.amazonaws.com" , " service2.amazonaws.com" ]
209- enabled_policy_types = [" SERVICE_CONTROL_POLICY" ]
208+ service_access_principals = [" service1.amazonaws.com" , " service2.amazonaws.com" ]
209+ enabled_policy_types = [" SERVICE_CONTROL_POLICY" ]
210210 expected_enabled_policy_types = [" SERVICE_CONTROL_POLICY" ]
211- feature_set = " ALL"
211+ feature_set = " ALL"
212212 }
213213
214214 module {
@@ -228,7 +228,7 @@ run "organization_feature_set_match" {
228228 service_access_principals = [" service1.amazonaws.com" , " service2.amazonaws.com" ]
229229 enabled_policy_types = [" SERVICE_CONTROL_POLICY" ]
230230 feature_set = " ALL"
231- expected_feature_set = " ALL"
231+ expected_feature_set = " ALL"
232232 }
233233
234234 module {
@@ -240,3 +240,173 @@ run "organization_feature_set_match" {
240240 error_message = " Feature set mismatch after creation"
241241 }
242242}
243+
244+ variables {
245+ tag_policy_content = << EOF
246+ {
247+ "Version": "2012-10-17",
248+ "Statement": [
249+ {
250+ "Effect": "Allow",
251+ "Action": "tag:GetResources",
252+ "Resource": "*"
253+ }
254+ ]
255+ }
256+ EOF
257+ }
258+
259+ run "policy_name_match" {
260+ command = plan
261+
262+ module {
263+ source = " ./modules/policy/"
264+ }
265+
266+ variables {
267+ content = var. tag_policy_content
268+ name = " STANDARD_TAG_POLICIES"
269+ description = " Recommend tag policies"
270+ type = " TAG_POLICY"
271+ expected_name = " STANDARD_TAG_POLICIES"
272+ tags = {
273+ " some_key_name" = " some_value"
274+ " another_key_name" = " another_value"
275+ }
276+ }
277+
278+ assert {
279+ condition = aws_organizations_policy. this . name == var. expected_name
280+ error_message = " Policy name mismatch after creation"
281+ }
282+ }
283+
284+ run "policy_content_match" {
285+ command = plan
286+
287+ module {
288+ source = " ./modules/policy/"
289+ }
290+
291+ variables {
292+ content = var. tag_policy_content
293+ name = " STANDARD_TAG_POLICIES"
294+ description = " Recommend tag policies"
295+ type = " TAG_POLICY"
296+ expected_content = var. tag_policy_content
297+ tags = {
298+ " some_key_name" = " some_value"
299+ " another_key_name" = " another_value"
300+ }
301+ }
302+
303+ assert {
304+ condition = aws_organizations_policy. this . content == var. expected_content
305+ error_message = " Policy content mismatch after creation"
306+ }
307+ }
308+
309+ run "policy_type_match" {
310+ command = plan
311+
312+ module {
313+ source = " ./modules/policy/"
314+ }
315+
316+ variables {
317+ content = var. tag_policy_content
318+ name = " STANDARD_TAG_POLICIES"
319+ description = " Recommend tag policies"
320+ type = " TAG_POLICY"
321+ expected_type = " TAG_POLICY"
322+ tags = {
323+ " some_key_name" = " some_value"
324+ " another_key_name" = " another_value"
325+ }
326+ }
327+
328+ assert {
329+ condition = aws_organizations_policy. this . type == var. expected_type
330+ error_message = " Policy type mismatch after creation"
331+ }
332+ }
333+
334+ run "policy_description_match" {
335+ command = plan
336+
337+ module {
338+ source = " ./modules/policy/"
339+ }
340+
341+ variables {
342+ content = var. tag_policy_content
343+ name = " STANDARD_TAG_POLICIES"
344+ description = " Recommend tag policies"
345+ expected_description = " Recommend tag policies"
346+ type = " TAG_POLICY"
347+ tags = {
348+ " some_key_name" = " some_value"
349+ " another_key_name" = " another_value"
350+ }
351+ }
352+
353+ assert {
354+ condition = aws_organizations_policy. this . description == var. expected_description
355+ error_message = " Policy description mismatch after creation"
356+ }
357+ }
358+
359+ run "policy_skip_destroy_match" {
360+ command = plan
361+
362+ module {
363+ source = " ./modules/policy/"
364+ }
365+
366+ variables {
367+ content = var. tag_policy_content
368+ name = " STANDARD_TAG_POLICIES"
369+ description = " Recommend tag policies"
370+ type = " TAG_POLICY"
371+ skip_destroy = true
372+ expected_skip_destroy = true
373+ tags = {
374+ " some_key_name" = " some_value"
375+ " another_key_name" = " another_value"
376+ }
377+ }
378+
379+ assert {
380+ condition = aws_organizations_policy. this . skip_destroy == var. expected_skip_destroy
381+ error_message = " Policy skip_destroy mismatch after creation"
382+ }
383+ }
384+
385+ run "policy_tags_match" {
386+ command = plan
387+
388+ module {
389+ source = " ./modules/policy/"
390+ }
391+
392+ variables {
393+ content = var. tag_policy_content
394+ name = " STANDARD_TAG_POLICIES"
395+ description = " Recommend tag policies"
396+ type = " TAG_POLICY"
397+ tags = {
398+ " some_key_name" = " some_value"
399+ " another_key_name" = " another_value"
400+ }
401+ }
402+
403+ assert {
404+ condition = aws_organizations_policy. this . tags [" some_key_name" ] == " some_value"
405+ error_message = " Tag 'some_key_name' with value 'some_value' is missing or incorrect"
406+ }
407+
408+ assert {
409+ condition = aws_organizations_policy. this . tags [" another_key_name" ] == " another_value"
410+ error_message = " Tag 'another_key_name' with value 'another_value' is missing or incorrect"
411+ }
412+ }
0 commit comments