Skip to content

Commit e6df5e6

Browse files
committed
extract unit tests based on modules
1 parent 3d9aac6 commit e6df5e6

6 files changed

+467
-474
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
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+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
run "organizationalUnit_name_match" {
2+
command = plan
3+
4+
module {
5+
source = "./modules/organizational_unit/"
6+
}
7+
8+
variables {
9+
name = "some_organizationUnit_name"
10+
parent_id = "ou-rndm-parentid"
11+
tags = {
12+
"some_key_name" = "some_value"
13+
"another_key_name" = "another_value"
14+
}
15+
expected_name = "some_organizationUnit_name"
16+
}
17+
18+
assert {
19+
condition = aws_organizations_organizational_unit.org_unit.name == var.expected_name
20+
error_message = "Organization unit name mismatch after creation"
21+
}
22+
}
23+
24+
run "organizationalUnit_parentId_match" {
25+
command = plan
26+
27+
module {
28+
source = "./modules/organizational_unit/"
29+
}
30+
31+
variables {
32+
name = "some_organizationUnit_name"
33+
parent_id = "ou-rndm-parentid"
34+
tags = {
35+
"some_key_name" = "some_value"
36+
"another_key_name" = "another_value"
37+
}
38+
expected_parent_id = "ou-rndm-parentid"
39+
}
40+
41+
assert {
42+
condition = aws_organizations_organizational_unit.org_unit.parent_id == var.expected_parent_id
43+
error_message = "Organization unit name mismatch after creation"
44+
}
45+
}
46+
47+
run "organizationalUnit_tags_match" {
48+
command = plan
49+
50+
module {
51+
source = "./modules/organizational_unit/"
52+
}
53+
54+
variables {
55+
name = "some_organizationUnit_name"
56+
parent_id = "ou-rndm-parentid"
57+
tags = {
58+
"some_key_name" = "some_value"
59+
"another_key_name" = "another_value"
60+
}
61+
}
62+
63+
assert {
64+
condition = aws_organizations_organizational_unit.org_unit.tags["some_key_name"] == "some_value"
65+
error_message = "Tag 'some_key_name' with value 'some_value' is missing or incorrect"
66+
}
67+
assert {
68+
condition = aws_organizations_organizational_unit.org_unit.tags["another_key_name"] == "another_value"
69+
error_message = "Tag 'another_key_name' with value 'another_value' is missing or incorrect"
70+
}
71+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
run "organization_aws_service_access_principals_match" {
2+
command = plan
3+
4+
variables {
5+
service_access_principals = ["service1.amazonaws.com", "service2.amazonaws.com"]
6+
expected_aws_service_access_principals = ["service1.amazonaws.com", "service2.amazonaws.com"]
7+
enabled_policy_types = ["SERVICE_CONTROL_POLICY"]
8+
feature_set = "ALL"
9+
}
10+
11+
module {
12+
source = "./"
13+
}
14+
15+
assert {
16+
condition = toset(aws_organizations_organization.org.aws_service_access_principals) == toset(var.expected_aws_service_access_principals)
17+
error_message = "AWS service access principals mismatch after creation"
18+
}
19+
}
20+
21+
run "organization_enabled_policy_types_match" {
22+
command = plan
23+
24+
variables {
25+
service_access_principals = ["service1.amazonaws.com", "service2.amazonaws.com"]
26+
enabled_policy_types = ["SERVICE_CONTROL_POLICY"]
27+
expected_enabled_policy_types = ["SERVICE_CONTROL_POLICY"]
28+
feature_set = "ALL"
29+
}
30+
31+
module {
32+
source = "./"
33+
}
34+
35+
assert {
36+
condition = toset(aws_organizations_organization.org.enabled_policy_types) == toset(var.expected_enabled_policy_types)
37+
error_message = "Enabled policy types mismatch after creation"
38+
}
39+
}
40+
41+
run "organization_feature_set_match" {
42+
command = plan
43+
44+
variables {
45+
service_access_principals = ["service1.amazonaws.com", "service2.amazonaws.com"]
46+
enabled_policy_types = ["SERVICE_CONTROL_POLICY"]
47+
feature_set = "ALL"
48+
expected_feature_set = "ALL"
49+
}
50+
51+
module {
52+
source = "./"
53+
}
54+
55+
assert {
56+
condition = aws_organizations_organization.org.feature_set == var.expected_feature_set
57+
error_message = "Feature set mismatch after creation"
58+
}
59+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
run "policy_attachment_policy_id_match" {
2+
command = plan
3+
4+
module {
5+
source = "./modules/policy_attachment/"
6+
}
7+
8+
variables {
9+
policy_id = "p-12345678"
10+
target_id = "r-1234"
11+
skip_destroy = true
12+
expected_policy_id = "p-12345678"
13+
}
14+
15+
assert {
16+
condition = aws_organizations_policy_attachment.this.policy_id == var.expected_policy_id
17+
error_message = "Policy ID mismatch after attachment"
18+
}
19+
}
20+
21+
run "policy_attachment_target_id_match" {
22+
command = plan
23+
24+
module {
25+
source = "./modules/policy_attachment/"
26+
}
27+
28+
variables {
29+
policy_id = "p-12345678"
30+
target_id = "r-1234"
31+
skip_destroy = true
32+
expected_target_id = "r-1234"
33+
}
34+
35+
assert {
36+
condition = aws_organizations_policy_attachment.this.target_id == var.expected_target_id
37+
error_message = "Target ID mismatch after attachment"
38+
}
39+
}
40+
41+
run "policy_attachment_skip_destroy_match" {
42+
command = plan
43+
44+
module {
45+
source = "./modules/policy_attachment/"
46+
}
47+
48+
variables {
49+
policy_id = "p-12345678"
50+
target_id = "r-1234"
51+
skip_destroy = true
52+
expected_skip_destroy = true
53+
}
54+
55+
assert {
56+
condition = aws_organizations_policy_attachment.this.skip_destroy == var.expected_skip_destroy
57+
error_message = "Skip destroy mismatch after attachment"
58+
}
59+
}

0 commit comments

Comments
 (0)