generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 3
/
user_roles_attachment_test.go
91 lines (81 loc) · 2.73 KB
/
user_roles_attachment_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package acc_tests
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"regexp"
"testing"
)
func TestAccResourceUserRolesAttachment(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: validateResourceDestroyed("user", "v1/users"),
Steps: []resource.TestStep{
{
Config: testAccResourceUserRoleAttachmentStep1,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(
"pfptmeta_user_roles_attachment.attachment", "user_id",
"pfptmeta_user.user", "id"),
resource.TestMatchResourceAttr(
"pfptmeta_user_roles_attachment.attachment", "roles.0", regexp.MustCompile("^rol-.+$")),
resource.TestMatchResourceAttr(
"pfptmeta_user_roles_attachment.attachment", "roles.1", regexp.MustCompile("^rol-.+$")),
),
},
{
Config: testAccResourceUserRoleAttachmentStep2,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(
"pfptmeta_user_roles_attachment.attachment", "user_id",
"pfptmeta_user.user", "id"),
resource.TestCheckResourceAttrPair(
"pfptmeta_user_roles_attachment.attachment", "roles.0",
"pfptmeta_role.metaport_role", "id"),
resource.TestCheckNoResourceAttr("pfptmeta_user_roles_attachment.attachment", "roles.1"),
),
},
},
})
}
const testAccResourceUserRoleAttachmentStep1 = `
resource "pfptmeta_user" "user" {
given_name = "John"
family_name = "Smith"
email = "john.smith@example.com"
}
resource "pfptmeta_role" "metaport_role" {
name = "metaport role"
apply_to_orgs = ["org-31126"]
privileges = ["metaports:read", "metaports:write"]
}
resource "pfptmeta_role" "network_element_role" {
name = "network element role"
apply_to_orgs = ["org-31126"]
privileges = ["network_elements:read", "network_elements:write"]
}
resource "pfptmeta_user_roles_attachment" "attachment" {
user_id = pfptmeta_user.user.id
roles = [pfptmeta_role.metaport_role.id, pfptmeta_role.network_element_role.id]
}
`
const testAccResourceUserRoleAttachmentStep2 = `
resource "pfptmeta_user" "user" {
given_name = "John"
family_name = "Smith"
email = "john.smith@example.com"
}
resource "pfptmeta_role" "metaport_role" {
name = "metaport role"
apply_to_orgs = ["org-31126"]
privileges = ["metaports:read", "metaports:write"]
}
resource "pfptmeta_role" "network_element_role" {
name = "network element role"
apply_to_orgs = ["org-31126"]
privileges = ["network_elements:read", "network_elements:write"]
}
resource "pfptmeta_user_roles_attachment" "attachment" {
user_id = pfptmeta_user.user.id
roles = [pfptmeta_role.metaport_role.id]
}
`