Skip to content

Commit

Permalink
Merge pull request #23 from cgroschupp/add-group-type
Browse files Browse the repository at this point in the history
Add group type
  • Loading branch information
barbaluc authored Jul 19, 2021
2 parents 3b42614 + cc4a4b7 commit 61455db
Show file tree
Hide file tree
Showing 12 changed files with 234 additions and 90 deletions.
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
HOSTNAME=github.com
NAMESPACE=Ouest-France
NAME=ldap
BINARY=terraform-provider-${NAME}
VERSION=0.8.0
OS_ARCH=linux_amd64

default: install

build:
go build -o terraform-provider-ldap_v0.0.1
go build -o ${BINARY}

install: build
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
mv ${BINARY} ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}

generate-docs:
tfplugindocs
32 changes: 23 additions & 9 deletions docs/data-sources/group.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
# ldap_group Data Source
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "ldap_group Data Source - terraform-provider-ldap"
subcategory: ""
description: |-
ldap_group is a data source for managing an LDAP group.
---

# ldap_group (Data Source)

`ldap_group` is a data source for managing an LDAP group.

## Example Usage

```hcl
```terraform
data "ldap_group" "group" {
ou = "OU=MyOU,DC=domain,DC=tld"
name = "MyGroup"
}
```

## Argument Reference
<!-- schema generated by tfplugindocs -->
## Schema

### Required

- **name** (String) LDAP group name.
- **ou** (String) OU where LDAP group will be search.

### Read-Only

* `ou` - (Required) OU where LDAP group will be created.
* `name` - (Required) LDAP group name.
- **description** (String) Description attribute for the LDAP
- **group_type** (String) Type of the group
- **id** (String) The DN of the LDAP group.
- **members** (Set of String) LDAP group members.

## Attribute Reference

* `id` - LDAP group DN.
* `members` - LDAP group members.
* `description` - Description attribute for the LDAP group.
36 changes: 26 additions & 10 deletions docs/data-sources/user.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
# ldap_user Data Source
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "ldap_user Data Source - terraform-provider-ldap"
subcategory: ""
description: |-
ldap_user is a data source for retrieving an LDAP user.
---

# ldap_user (Data Source)

`ldap_user` is a data source for retrieving an LDAP user.

## Example Usage

```hcl
```terraform
data "ldap_user" "user" {
ou = "OU=MyOU,DC=domain,DC=tld"
name = "MyUser"
}
```

## Argument Reference
<!-- schema generated by tfplugindocs -->
## Schema

### Required

- **ou** (String) OU where LDAP user will be search.

### Optional

- **description** (String) Description attribute for the LDAP user.
- **name** (String) The name of the LDAP user.
- **sam_account_name** (String) The sAMAccountName of the LDAP user.
- **user_principal_name** (String) The userPrincipalName of the LDAP user

### Read-Only

* `ou` - (Required) OU where LDAP user will be search.
* `name` - (Optional) The name of the LDAP user.
* `sam_account_name` - (Optional) The sAMAccountName of the LDAP user.
* `user_principal_name` - (Optional) The userPrincipalName of the LDAP user.
- **id** (String) The DN of the LDAP user.

## Attribute Reference

* `id` - LDAP user DN.
* `description` - Description attribute for the LDAP user.
33 changes: 22 additions & 11 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
---
layout: ""
page_title: "LDAP Provider"
description: |-
The LDAP provider is used to interact with any ActiveDirectory server.
---

# LDAP Provider

The LDAP provider is used to interact with any ActiveDirectory server.

## Example Usage

```hcl
```terraform
# Provider configuration
terraform {
required_providers {
Expand All @@ -20,16 +27,20 @@ provider "ldap" {
bind_user = "ldap_user"
bind_password = "ldap_password"
}
...
```

## Argument Reference
<!-- schema generated by tfplugindocs -->
## Schema

### Required

- **bind_password** (String) LDAP password
- **bind_user** (String) LDAP username
- **host** (String) LDAP host
- **port** (Number) LDAP port

### Optional

* `host` - (Required) LDAP host address formatted like `ldap.mycompany.com`.
* `port` - (Required) LDAP port.
* `bind_user` - (Required) LDAP bind user.
* `bind_password` - (Required) LDAP bind password.
* `tls` - (Optional) Enable the TLS encryption for LDAP (LDAPS). Default, is `false`.
* `tls_ca_certificate` - (Optional) The TLS CA certificate to trust for the LDAPS connection.
* `tls_insecure` - (Optional) Don't verify the server TLS certificate. Default is `false`.
- **tls** (Boolean) Enable the TLS encryption for LDAP (LDAPS). Default, is `false`.
- **tls_ca_certificate** (String) The TLS CA certificate to trust for the LDAPS connection.
- **tls_insecure** (Boolean) Don't verify the server TLS certificate. Default is `false`.
37 changes: 23 additions & 14 deletions docs/resources/group.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# ldap_group
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "ldap_group Resource - terraform-provider-ldap"
subcategory: ""
description: |-
ldap_group is a resource for managing an LDAP group.
---

# ldap_group (Resource)

`ldap_group` is a resource for managing an LDAP group.

## Example Usage

```hcl
```terraform
resource "ldap_group" "group" {
ou = "OU=MyOU,DC=domain,DC=tld"
name = "MyGroup"
Expand All @@ -13,21 +21,22 @@ resource "ldap_group" "group" {
}
```

## Argument Reference
<!-- schema generated by tfplugindocs -->
## Schema

* `ou` - (Required) OU where LDAP group will be created.
* `name` - (Required) LDAP group name.
* `members` - (Optional) LDAP group members.
* `description` - (Optional) Description attribute for the LDAP group.
### Required

## Attribute Reference
- **name** (String) LDAP group name.
- **ou** (String) OU where LDAP group will be created.

* `id` - LDAP group DN.
### Optional

## Import
- **description** (String) Description attribute for the LDAP group.
- **group_type** (String) Type of the group
- **members** (Set of String) LDAP group members.

### Read-Only

- **id** (String) The DN of the LDAP group.

LDAP group can be imported using the full LDAP DN (`id`), e.g.

```
$ terraform import ldap_group.example CN=MyGroup,OU=MyOU,DC=domain,DC=tld
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Ouest-France/terraform-provider-ldap
go 1.13

require (
github.com/Ouest-France/goldap v0.5.2
github.com/Ouest-France/goldap v0.5.3
github.com/go-ldap/ldap/v3 v3.3.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.6.1
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF0
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0=
github.com/Ouest-France/goldap v0.5.2 h1:0EjHUGlD4Yei9YE1SaQeX/Ql7iriR6kplhL2pTttnCY=
github.com/Ouest-France/goldap v0.5.2/go.mod h1:QJH+Ft6452W7+EZAr1kPgaQqJFlM5ZgdtbCFXpYi/nY=
github.com/Ouest-France/goldap v0.5.3 h1:+Kj5LsLxlrQivb0cB4z0dxm2ADZ/f1355kX5+qW+9sw=
github.com/Ouest-France/goldap v0.5.3/go.mod h1:QJH+Ft6452W7+EZAr1kPgaQqJFlM5ZgdtbCFXpYi/nY=
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
Expand Down
31 changes: 23 additions & 8 deletions ldap/data_source_resource_ldap_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,43 @@ import (

func dataSourceLDAPGroup() *schema.Resource {
return &schema.Resource{
Description: "`ldap_group` is a data source for managing an LDAP group.",
ReadContext: dataSourceLDAPGroupRead,

Schema: map[string]*schema.Schema{
"id": {
Description: "The DN of the LDAP group.",
Type: schema.TypeString,
Computed: true,
},
"ou": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "OU where LDAP group will be search.",
Type: schema.TypeString,
Required: true,
},
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "LDAP group name.",
Type: schema.TypeString,
Required: true,
},
"description": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Description attribute for the LDAP",
Type: schema.TypeString,
Computed: true,
},
"members": &schema.Schema{
Type: schema.TypeSet,
Computed: true,
Description: "LDAP group members.",
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"group_type": &schema.Schema{
Description: "Type of the group",
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down
37 changes: 24 additions & 13 deletions ldap/data_source_resource_ldap_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,39 @@ import (

func dataSourceLDAPUser() *schema.Resource {
return &schema.Resource{
Description: "`ldap_user` is a data source for retrieving an LDAP user.",
ReadContext: dataSourceLDAPUserRead,
Schema: map[string]*schema.Schema{
"ou": &schema.Schema{
Type: schema.TypeString,
Required: true,
"id": {
Description: "The DN of the LDAP user.",
Type: schema.TypeString,
Computed: true,
},
"name": &schema.Schema{
"ou": {
Description: "OU where LDAP user will be search.",
Type: schema.TypeString,
Required: true,
},
"name": {
Description: "The name of the LDAP user.",
Type: schema.TypeString,
Optional: true,
ExactlyOneOf: []string{"name", "sam_account_name", "user_principal_name"},
},
"sam_account_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
"sam_account_name": {
Description: "The sAMAccountName of the LDAP user.",
Type: schema.TypeString,
Optional: true,
},
"user_principal_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
"user_principal_name": {
Description: "The userPrincipalName of the LDAP user",
Type: schema.TypeString,
Optional: true,
},
"description": &schema.Schema{
Type: schema.TypeString,
Optional: true,
"description": {
Description: "Description attribute for the LDAP user.",
Type: schema.TypeString,
Optional: true,
},
},
}
Expand Down
14 changes: 7 additions & 7 deletions ldap/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,38 @@ import (
func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"host": &schema.Schema{
"host": {
Type: schema.TypeString,
Required: true,
Description: "LDAP host",
},
"port": &schema.Schema{
"port": {
Type: schema.TypeInt,
Required: true,
Description: "LDAP port",
},
"bind_user": &schema.Schema{
"bind_user": {
Type: schema.TypeString,
Required: true,
Description: "LDAP username",
},
"bind_password": &schema.Schema{
"bind_password": {
Type: schema.TypeString,
Required: true,
Description: "LDAP password",
},
"tls": &schema.Schema{
"tls": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable the TLS encryption for LDAP (LDAPS). Default, is `false`.",
},
"tls_ca_certificate": &schema.Schema{
"tls_ca_certificate": {
Type: schema.TypeString,
Optional: true,
Description: "The TLS CA certificate to trust for the LDAPS connection.",
},
"tls_insecure": &schema.Schema{
"tls_insecure": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Expand Down
Loading

0 comments on commit 61455db

Please sign in to comment.