Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add property custom_user_ou to vcd_org_ldap #1142

Merged
merged 7 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changes/v3.11.0/1119-bug-fixes.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* Fix media item detection in `vcd_resource_list`: it was incorrectly listing also vApp templates [GH-1101]
* Fix media item detection in `vcd_resource_list`: it was incorrectly listing also vApp templates [GH-1119]
1 change: 1 addition & 0 deletions .changes/v3.11.0/1142-bug-fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Fix Issue [1134](https://github.com/vmware/terraform-provider-vcd/issues/1134) : Can't use SYSTEM `ldap_mode` [GH-1142]
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ require (
google.golang.org/grpc v1.56.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)

replace github.com/vmware/go-vcloud-director/v2 => github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20231025153938-20fd2086dd79

// replace github.com/vmware/go-vcloud-director/v2 => ../go-vcloud-director
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtM
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20231025153938-20fd2086dd79 h1:gDLvsR112oR/W0YgIHPfUW5SOU0V5viCc7BUQFjpfDs=
github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20231025153938-20fd2086dd79/go.mod h1:QPxGFgrUcSyzy9IlpwDE4UNT3tsOy2047tJOPEJ4nlw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -123,8 +125,6 @@ github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/vmware/go-vcloud-director/v2 v2.22.0-alpha.8 h1:SJZtJpYMj+I320FS6PrOQTKlYuQSnUdy0RI+3ZcKvGg=
github.com/vmware/go-vcloud-director/v2 v2.22.0-alpha.8/go.mod h1:QPxGFgrUcSyzy9IlpwDE4UNT3tsOy2047tJOPEJ4nlw=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/zclconf/go-cty v1.13.2 h1:4GvrUxe/QUDYuJKAav4EYqdM47/kZa672LwmXFmEKT0=
github.com/zclconf/go-cty v1.13.2/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0=
Expand Down
5 changes: 5 additions & 0 deletions vcd/datasource_vcd_org_ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ func datasourceVcdOrgLdap() *schema.Resource {
Computed: true,
Description: "Type of LDAP settings (one of NONE, SYSTEM, CUSTOM)",
},
"custom_user_ou": { // CustomUsersOu
Type: schema.TypeString,
Computed: true,
Description: "If ldap_mode is SYSTEM, specifies a LDAP attribute=value pair to use for OU (organizational unit)",
},
"custom_settings": { // CustomOrgLdapSettings
Type: schema.TypeList,
Computed: true,
Expand Down
11 changes: 11 additions & 0 deletions vcd/resource_vcd_org_ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ func resourceVcdOrgLdap() *schema.Resource {
Description: "Type of LDAP settings (one of NONE, SYSTEM, CUSTOM)",
ValidateFunc: validation.StringInSlice([]string{types.LdapModeNone, types.LdapModeSystem, types.LdapModeCustom}, false),
},
"custom_user_ou": { // CustomUsersOu
Type: schema.TypeString,
Optional: true,
Description: "If ldap_mode is SYSTEM, specifies a LDAP attribute=value pair to use for OU (organizational unit)",
},
"custom_settings": { // CustomOrgLdapSettings
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -261,6 +266,7 @@ func genericVcdOrgLdapRead(ctx context.Context, d *schema.ResourceData, meta int

dSet(d, "org_id", orgId)
dSet(d, "ldap_mode", config.OrgLdapMode)
dSet(d, "custom_user_ou", config.CustomUsersOu)
d.SetId(adminOrg.AdminOrg.ID)

if config.OrgLdapMode == "CUSTOM" {
Expand Down Expand Up @@ -330,6 +336,11 @@ func fillLdapSettings(d *schema.ResourceData) (*types.OrgLdapSettingsType, error
OrgLdapMode: d.Get("ldap_mode").(string),
}

if settings.OrgLdapMode == "SYSTEM" {
settings.CustomUsersOu = d.Get("custom_user_ou").(string)
return &settings, nil
}

if settings.OrgLdapMode != "CUSTOM" {
return &settings, nil
}
Expand Down
27 changes: 26 additions & 1 deletion vcd/resource_vcd_org_ldap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ func TestAccVcdOrgLdap(t *testing.T) {
params["FuncName"] = t.Name()
configText := templateFill(testAccOrgLdap, params)

params["FuncName"] = t.Name() + "-Sys"
configTextSystem := templateFill(testAccOrgLdapSystem, params)

params["FuncName"] = t.Name() + "-DS"
configTextDS := templateFill(testAccOrgLdap+testAccOrgLdapDS, params)
if vcdShortTest {
t.Skip(acceptanceTestsSkipped)
return
}
debugPrintf("#[DEBUG] CONFIGURATION Resource: %s\n", configText)
debugPrintf("#[DEBUG] CONFIGURATION Resource (Custom): %s\n", configText)
debugPrintf("#[DEBUG] CONFIGURATION Resource (System): %s\n", configTextSystem)
debugPrintf("#[DEBUG] CONFIGURATION Data source: %s\n", configTextDS)

orgDsDef := "data.vcd_org." + orgName
Expand Down Expand Up @@ -83,6 +87,15 @@ func TestAccVcdOrgLdap(t *testing.T) {
ImportStateVerify: true,
ImportStateIdFunc: importStateIdTopHierarchy(orgName),
},
{
Config: configTextSystem,
Check: resource.ComposeTestCheckFunc(
testAccCheckOrgLdapExists(ldapResourceDef),
resource.TestCheckResourceAttr(orgDsDef, "name", testConfig.VCD.Org),
resource.TestCheckResourceAttr(ldapResourceDef, "ldap_mode", "SYSTEM"),
resource.TestCheckResourceAttrPair(orgDsDef, "id", ldapResourceDef, "org_id"),
),
},
},
})
postTestChecks(t)
Expand Down Expand Up @@ -188,6 +201,18 @@ resource "vcd_org_ldap" "{{.OrgName}}" {
}
`

const testAccOrgLdapSystem = `
data "vcd_org" "{{.OrgName}}" {
name = "{{.OrgName}}"
}

resource "vcd_org_ldap" "{{.OrgName}}" {
org_id = data.vcd_org.{{.OrgName}}.id
ldap_mode = "SYSTEM"
custom_user_ou = "ou=Foo,dc=domain,dc=local base DN"
}
`

const testAccOrgLdapDS = `
# skip-binary-test: Terraform resource cannot have resource and datasource in the same file
data "vcd_org_ldap" "{{.OrgName}}-DS" {
Expand Down
17 changes: 16 additions & 1 deletion website/docs/r/org_ldap.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Supported in provider *v3.8+*

-> **Note:** This resource requires system administrator privileges.

## Example Usage
## Example Usage 1 - Custom configuration

```hcl
provider "vcd" {
Expand Down Expand Up @@ -80,12 +80,27 @@ resource "vcd_org_ldap" "my-org-ldap" {
}
```

## Example Usage 2 - Using system configuration

```hcl
data "vcd_org" "my-org" {
name = "my-org"
}

resource "vcd_org_ldap" "my-org-ldap" {
org_id = data.vcd_org.my-org.id
ldap_mode = "SYSTEM"
custom_user_ou = "ou=Foo,dc=domain,dc=local base DN"
}
```

## Argument Reference

The following arguments are supported:

* `org_id` - (Required) Org ID: there is only one LDAP configuration available for an organization. Thus, the resource can be identified by the Org.
* `ldap_mode` - (Required) One of `NONE`, `CUSTOM`, `SYSTEM`. Note that using `NONE` has the effect of removing the LDAP settings
* `custom_user_ou` - (Optional) If `ldap_mode` is `SYSTEM`, specifies a LDAP `attribute=value` pair to use for OU (organizational unit)
lvirbalas marked this conversation as resolved.
Show resolved Hide resolved
* `custom_settings` - (Optional) LDAP server configuration. Becomes mandatory if `ldap_mode` is set to `CUSTOM`. See [Custom Settings](#custom-settings) below for details

<a id="custom-settings"></a>
Expand Down