-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1ad96e4
Showing
8 changed files
with
679 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: PR | ||
on: [pull_request] | ||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up Go 1.13 | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: 1.13 | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v1 | ||
|
||
- name: Build | ||
run: go build -o terraform-provider-ldap_${GITHUB_REF} | ||
|
||
- name: Setup Lint | ||
run: curl -LO https://github.com/golangci/golangci-lint/releases/download/v1.19.1/golangci-lint-1.19.1-linux-amd64.tar.gz && tar -xf golangci-lint-1.19.1-linux-amd64.tar.gz | ||
|
||
- name: Lint | ||
run: golangci-lint-1.19.1-linux-amd64/golangci-lint run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Tag | ||
on: | ||
push: | ||
tags: | ||
- "v*.*.*" | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up Go 1.13 | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: 1.13 | ||
id: go | ||
|
||
- name: Get the version | ||
id: get_version | ||
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v1 | ||
|
||
- name: Build | ||
run: go build -o terraform-provider-ldap_${{ steps.get_version.outputs.VERSION }} | ||
|
||
- name: Setup Lint | ||
run: curl -LO https://github.com/golangci/golangci-lint/releases/download/v1.19.1/golangci-lint-1.19.1-linux-amd64.tar.gz && tar -xf golangci-lint-1.19.1-linux-amd64.tar.gz | ||
|
||
- name: Lint | ||
run: golangci-lint-1.19.1-linux-amd64/golangci-lint run | ||
|
||
- name: Upload binaries to release | ||
uses: svenstaro/upload-release-action@v1-release | ||
with: | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
file: terraform-provider-ldap_${{ steps.get_version.outputs.VERSION }} | ||
asset_name: terraform-provider-ldap_${{ steps.get_version.outputs.VERSION }} | ||
tag: ${{ github.ref }} | ||
overwrite: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build: | ||
go build -o terraform-provider-ldap_v0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module github.com/Ouest-France/terraform-provider-ldap | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/Ouest-France/goldap v0.1.0 | ||
github.com/go-ldap/ldap/v3 v3.1.3 | ||
github.com/hashicorp/terraform v0.12.16 | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package ldap | ||
|
||
import ( | ||
"github.com/Ouest-France/goldap" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func Provider() *schema.Provider { | ||
return &schema.Provider{ | ||
Schema: map[string]*schema.Schema{ | ||
"host": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "LDAP host", | ||
}, | ||
"port": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Required: true, | ||
Description: "LDAP port", | ||
}, | ||
"bind_user": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "FortiADC username", | ||
}, | ||
"bind_password": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "FortiADC password", | ||
}, | ||
"tls": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: false, | ||
Description: "Disable TLS Verify", | ||
}, | ||
}, | ||
ResourcesMap: map[string]*schema.Resource{ | ||
"ldap_group": resourceLDAPGroup(), | ||
}, | ||
ConfigureFunc: providerConfigure, | ||
} | ||
} | ||
|
||
func providerConfigure(d *schema.ResourceData) (interface{}, error) { | ||
|
||
client := &goldap.Client{ | ||
Host: d.Get("host").(string), | ||
Port: d.Get("port").(int), | ||
BindUser: d.Get("bind_user").(string), | ||
BindPassword: d.Get("bind_password").(string), | ||
TLS: d.Get("tls").(bool), | ||
} | ||
|
||
err := client.Connect() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return client, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package ldap | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Ouest-France/goldap" | ||
"github.com/go-ldap/ldap/v3" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func resourceLDAPGroup() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceLDAPGroupCreate, | ||
Read: resourceLDAPGroupRead, | ||
Delete: resourceLDAPGroupDelete, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"ou": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"members": &schema.Schema{ | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
ForceNew: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceLDAPGroupCreate(d *schema.ResourceData, m interface{}) error { | ||
client := m.(*goldap.Client) | ||
|
||
dn := fmt.Sprintf("CN=%s,%s", d.Get("name").(string), d.Get("ou").(string)) | ||
|
||
members := []string{} | ||
memberSet := d.Get("members").(*schema.Set) | ||
for _, member := range memberSet.List() { | ||
members = append(members, member.(string)) | ||
} | ||
|
||
err := client.CreateGroup(dn, d.Get("name").(string), members) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(dn) | ||
|
||
return resourceLDAPGroupRead(d, m) | ||
} | ||
|
||
func resourceLDAPGroupRead(d *schema.ResourceData, m interface{}) error { | ||
client := m.(*goldap.Client) | ||
|
||
dn := fmt.Sprintf("CN=%s,%s", d.Get("name").(string), d.Get("ou").(string)) | ||
|
||
attributes, err := client.ReadGroup(dn) | ||
if err != nil { | ||
if err.(*ldap.Error).ResultCode == 32 { | ||
// Object doesn't exist | ||
d.SetId("") | ||
} | ||
} | ||
|
||
members := []string{} | ||
for name, values := range attributes { | ||
|
||
if name == "member" && len(values) >= 1 { | ||
members = append(members, values...) | ||
} | ||
} | ||
err = d.Set("members", members) | ||
|
||
return err | ||
} | ||
|
||
func resourceLDAPGroupDelete(d *schema.ResourceData, m interface{}) error { | ||
client := m.(*goldap.Client) | ||
|
||
dn := fmt.Sprintf("CN=%s,%s", d.Get("name").(string), d.Get("ou").(string)) | ||
|
||
err := client.DeleteGroup(dn) | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/Ouest-France/terraform-provider-ldap/ldap" | ||
|
||
"github.com/hashicorp/terraform/plugin" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func main() { | ||
plugin.Serve(&plugin.ServeOpts{ | ||
ProviderFunc: func() terraform.ResourceProvider { | ||
return ldap.Provider() | ||
}, | ||
}) | ||
} |