Skip to content

Commit 677aea2

Browse files
author
Han Zhou
committed
rebased with main branch, and updated docs and access_level field
1 parent 3545901 commit 677aea2

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

docs/resources/group_ldap_link.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ resource "gitlab_group_ldap_link" "test" {
3737
- **group_access** (String) Minimum access level for members of the LDAP group. Valid values are: `no one`, `minimal`, `guest`, `reporter`, `developer`, `maintainer`, `owner`, `master`
3838
- **id** (String) The ID of this resource.
3939

40-
GitLab group ldap links can be imported using an id made up of `group_id:ldap_provider:cn`, e.g.
40+
## Import
41+
42+
Import is supported using the following syntax:
4143

4244
```shell
45+
# GitLab group ldap links can be imported using an id made up of `group_id:ldap_provider:cn`, e.g.
4346
terraform import gitlab_group_ldap_link.test "12345:ldapmain:testuser"
4447
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# GitLab group ldap links can be imported using an id made up of `group_id:ldap_provider:cn`, e.g.
2+
terraform import gitlab_group_ldap_link.test "12345:ldapmain:testuser"

internal/provider/resource_gitlab_group_ldap_link.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var _ = registerResource("gitlab_group_ldap_link", func() *schema.Resource {
2121
ReadContext: resourceGitlabGroupLdapLinkRead,
2222
DeleteContext: resourceGitlabGroupLdapLinkDelete,
2323
Importer: &schema.ResourceImporter{
24-
State: resourceGitlabGroupLdapLinkImporter,
24+
StateContext: resourceGitlabGroupLdapLinkImporter,
2525
},
2626

2727
Schema: map[string]*schema.Schema{
@@ -184,10 +184,10 @@ func resourceGitlabGroupLdapLinkDelete(ctx context.Context, d *schema.ResourceDa
184184
return nil
185185
}
186186

187-
func resourceGitlabGroupLdapLinkImporter(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, diag.Diagnostics) {
187+
func resourceGitlabGroupLdapLinkImporter(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
188188
parts := strings.SplitN(d.Id(), ":", 3)
189189
if len(parts) != 3 {
190-
return nil, diag.FromErr(fmt.Errorf("invalid ldap link import id (should be <group id>:<ldap provider>:<ladp cn>): %s", d.Id()))
190+
return nil, fmt.Errorf("invalid ldap link import id (should be <group id>:<ldap provider>:<ladp cn>): %s", d.Id())
191191
}
192192

193193
groupId, ldapProvider, ldapCN := parts[0], parts[1], parts[2]
@@ -196,5 +196,8 @@ func resourceGitlabGroupLdapLinkImporter(ctx context.Context, d *schema.Resource
196196
d.Set("force", false)
197197

198198
diag := resourceGitlabGroupLdapLinkRead(ctx, d, meta)
199-
return []*schema.ResourceData{d}, diag
199+
if diag.HasError() {
200+
return nil, fmt.Errorf("%s", diag[0].Summary)
201+
}
202+
return []*schema.ResourceData{d}, nil
200203
}

0 commit comments

Comments
 (0)