@@ -13,6 +13,7 @@ import (
13
13
14
14
func TestAccGitlabGroupLdapLink_basic (t * testing.T ) {
15
15
rInt := acctest .RandInt ()
16
+ resourceName := "gitlab_group_ldap_link.foo"
16
17
17
18
// PreCheck runs after Config so load test data here
18
19
var ldapLink gitlab.LDAPGroupLink
@@ -31,18 +32,27 @@ func TestAccGitlabGroupLdapLink_basic(t *testing.T) {
31
32
SkipFunc : isRunningInCE ,
32
33
Config : testAccGitlabGroupLdapLinkCreateConfig (rInt , & testLdapLink ),
33
34
Check : resource .ComposeTestCheckFunc (
34
- testAccCheckGitlabGroupLdapLinkExists ("gitlab_group_ldap_link.foo" , & ldapLink ),
35
+ testAccCheckGitlabGroupLdapLinkExists (resourceName , & ldapLink ),
35
36
testAccCheckGitlabGroupLdapLinkAttributes (& ldapLink , & testAccGitlabGroupLdapLinkExpectedAttributes {
36
37
accessLevel : fmt .Sprintf ("developer" ), // nolint // TODO: Resolve this golangci-lint issue: S1039: unnecessary use of fmt.Sprintf (gosimple)
37
38
})),
38
39
},
39
40
41
+ // Import the group LDAP link (re-uses testAccGitlabGroupLdapLinkCreateConfig for Config)
42
+ {
43
+ SkipFunc : isRunningInCE ,
44
+ ResourceName : resourceName ,
45
+ ImportStateIdFunc : getGitlabGroupLdapLinkImportID (resourceName ),
46
+ ImportState : true ,
47
+ ImportStateVerify : true ,
48
+ },
49
+
40
50
// Update the group LDAP link to change the access level (uses testAccGitlabGroupLdapLinkUpdateConfig for Config)
41
51
{
42
52
SkipFunc : isRunningInCE ,
43
53
Config : testAccGitlabGroupLdapLinkUpdateConfig (rInt , & testLdapLink ),
44
54
Check : resource .ComposeTestCheckFunc (
45
- testAccCheckGitlabGroupLdapLinkExists ("gitlab_group_ldap_link.foo" , & ldapLink ),
55
+ testAccCheckGitlabGroupLdapLinkExists (resourceName , & ldapLink ),
46
56
testAccCheckGitlabGroupLdapLinkAttributes (& ldapLink , & testAccGitlabGroupLdapLinkExpectedAttributes {
47
57
accessLevel : fmt .Sprintf ("maintainer" ), // nolint // TODO: Resolve this golangci-lint issue: S1039: unnecessary use of fmt.Sprintf (gosimple)
48
58
})),
@@ -51,6 +61,30 @@ func TestAccGitlabGroupLdapLink_basic(t *testing.T) {
51
61
})
52
62
}
53
63
64
+ func getGitlabGroupLdapLinkImportID (resourceName string ) resource.ImportStateIdFunc {
65
+ return func (s * terraform.State ) (string , error ) {
66
+ rs , ok := s .RootModule ().Resources [resourceName ]
67
+ if ! ok {
68
+ return "" , fmt .Errorf ("Not Found: %s" , resourceName )
69
+ }
70
+
71
+ groupID := rs .Primary .Attributes ["group_id" ]
72
+ if groupID == "" {
73
+ return "" , fmt .Errorf ("No group ID is set" )
74
+ }
75
+ ldapProvider := rs .Primary .Attributes ["ldap_provider" ]
76
+ if ldapProvider == "" {
77
+ return "" , fmt .Errorf ("No LDAP provider is set" )
78
+ }
79
+ ldapCN := rs .Primary .Attributes ["cn" ]
80
+ if ldapCN == "" {
81
+ return "" , fmt .Errorf ("No LDAP CN is set" )
82
+ }
83
+
84
+ return fmt .Sprintf ("%s:%s:%s" , groupID , ldapProvider , ldapCN ), nil
85
+ }
86
+ }
87
+
54
88
func testAccCheckGitlabGroupLdapLinkExists (resourceName string , ldapLink * gitlab.LDAPGroupLink ) resource.TestCheckFunc {
55
89
return func (s * terraform.State ) error {
56
90
// Clear the "found" LDAP link before checking for existence
0 commit comments