Skip to content

Commit

Permalink
refactoring (#11)
Browse files Browse the repository at this point in the history
* arrange same as `terraform-provider-scaffolding`'s directories

* rename set.NewSet -> set.New

* cosme

* ldap initialization changed to function from method

* copy from terraform-provider-scaffolding/.gitignore

* Support for Debuggable Provider Binaries

* Add terraform-plugin-docs

* Add docs

* use goreleaser to build

* Add editor config

* update test
  • Loading branch information
hkobayash authored Apr 1, 2021
1 parent 4c34c83 commit 7b53ea1
Show file tree
Hide file tree
Showing 27 changed files with 426 additions and 110 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8

[Makefile]
indent_style = tab

[*.yml]
indent_style = space
indent_size = 2
57 changes: 32 additions & 25 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.dll
*.exe
.DS_Store
example.tf
terraform.tfplan
terraform.tfstate
bin/
dist/
modules-dev/
/pkg/
website/.vagrant
website/.bundle
website/build
website/node_modules
.vagrant/
*.backup
./*.tfstate
.terraform/
*.log
*.bak
*~
.*.swp
.idea
*.iml
*.test
*.prof
*.iml

website/vendor

# Test exclusions
!command/test-fixtures/**/*.tfstate
!command/test-fixtures/**/.terraform/

# main executable on linux
terraform-provider-ldap
/dist
# Keep windows files with windows line endings
*.winfile eol=crlf
43 changes: 43 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
before:
hooks:
- go mod download
builds:
- env:
- CGO_ENABLED=0
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath
ldflags:
- -s -w
goos:
- freebsd
- windows
- linux
- darwin
goarch:
- amd64
- '386'
- arm
- arm64
ignore:
- goos: darwin
goarch: '386'
binary: '{{ .ProjectName }}_v{{ .Version }}'
archives:
- format: zip
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
checksum:
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
algorithm: sha256
signs:
- artifacts: checksum
args:
- "--batch"
- "--local-user"
- "{{ .Env.GPG_FINGERPRINT }}"
- "--output"
- "${signature}"
- "--detach-sign"
- "${artifact}"
changelog:
skip: true
33 changes: 33 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Acceptance Tests",
"type": "go",
"request": "launch",
"mode": "test",
// this assumes your workspace is the root of the repo
"program": "${fileDirname}",
"env": {
"TF_ACC": "1",
},
"args": [],
},
{
"name": "Debug - Attach External CLI",
"type": "go",
"request": "launch",
"mode": "debug",
// this assumes your workspace is the root of the repo
"program": "${workspaceFolder}",
"env": {},
"args": [
// pass the debug flag for reattaching
"-debug",
],
}
]
}
18 changes: 6 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
BINARY=terraform-provider-ldap
PLUGIN_PATH=$(HOME)/.terraform.d/plugins/registry.terraform.io/elastic-infra/ldap/$(shell git describe --tags | tr -d v)/darwin_amd64
TEST_ENV := LDAP_HOST=localhost LDAP_PORT=389 LDAP_BIND_USER="cn=admin,dc=example,dc=com" LDAP_BIND_PASSWORD=admin
VERSION := v1.1.0

.DEFAULT_GOAL: $(BINARY)

$(BINARY):
go build -o bin/$(BINARY)

bootstrap:
go install github.com/mitchellh/gox

cross-build:
rm -rf dist
CGO_ENABLED=0 GOFLAGS="-trimpath" gox -osarch "linux/amd64 darwin/amd64" \
-output "dist/{{.OS}}_{{.Arch}}/$(BINARY)_$(VERSION)" \
-ldflags "-w -s"
tar cvzf $(BINARY)_$(VERSION).tar.gz -C dist .
install: $(BINARY)
install -d $(PLUGIN_PATH)
install -m 775 bin/$(BINARY) $(PLUGIN_PATH)/

test:
go test -v
go test -v ./...

docker_test:
$(TEST_ENV) go test -v
$(TEST_ENV) go test -v ./...
47 changes: 47 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
page_title: "LDAP Provider"
subcategory: ""
description: |-
The LDAP provider provides resources to interact with a LDAP object.
---

# LDAP Provider

The LDAP provider provides resources to interact with a LDAP object.

## Example Usage

```terraform
terraform {
required_providers {
ldap = {
source = "elastic-infra/ldap"
version = "~> 2.0"
}
}
}
provider "ldap" {
ldap_host = "localhost"
ldap_port = 389
bind_user = "cn=admin,dc=example,dc=com"
bind_password = "admin"
}
```

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

### Required

- **bind_password** (String) Password to authenticate the Bind user.
- **bind_user** (String) Bind user to be used for authenticating on the LDAP server.
- **ldap_host** (String) The LDAP server to connect to.

### Optional

- **ldap_port** (Number) The LDAP protocol port (default: 389).
- **start_tls** (Boolean) Upgrade TLS to secure the connection (default: false).
- **tls** (Boolean) Enable TLS encryption for LDAP (LDAPS) (default: false).
- **tls_insecure** (Boolean) Don't verify server TLS certificate (default: false).
- **use_tls** (Boolean, Deprecated) Use TLS to secure the connection (default: true).
60 changes: 60 additions & 0 deletions docs/resources/object.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "ldap_object Resource - terraform-provider-ldap"
subcategory: ""
description: |-
Provides a LDAP Object.
---

# ldap_object (Resource)

Provides a LDAP Object.

## Example Usage

```terraform
resource "ldap_object" "users_example_com" {
dn = "ou=users,dc=example,dc=com"
object_classes = ["top", "organizationalUnit"]
}
resource "ldap_object" "a123456" {
dn = "uid=a123456,${ldap_object.users_example_com.dn}"
object_classes = ["inetOrgPerson", "posixAccount"]
attributes = [
{ sn = "Doe" },
{ givenName = "John" },
{ cn = "John Doe" },
{ displayName = "Mr. John K. Doe, esq." },
{ mail = "[email protected]" },
{ mail = "[email protected]" },
{ userPassword = "password" },
{ uidNumber = "1234" },
{ gidNumber = "1234" },
{ homeDirectory = "/home/jdoe" },
{ loginShell = "/bin/bash" }
]
}
```

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

### Required

- **dn** (String) The Distinguished Name (DN) of the object, as the concatenation of its RDN (unique among siblings) and its parent's DN.
- **object_classes** (Set of String) The set of classes this object conforms to (e.g. organizationalUnit, inetOrgPerson).

### Optional

- **attributes** (Set of Map of String) The map of attributes of this object; each attribute can be multi-valued.
- **id** (String) The ID of this resource.

## Import

Import is supported using the following syntax:

```shell
$ export TF_LDAP_IMPORTER_PATH=a123456.tf
$ terraform import ldap_object.a123456 uid=a123456,ou=users,dc=example,dc=com
```
15 changes: 15 additions & 0 deletions examples/provider/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
terraform {
required_providers {
ldap = {
source = "elastic-infra/ldap"
version = "~> 2.0"
}
}
}

provider "ldap" {
ldap_host = "localhost"
ldap_port = 389
bind_user = "cn=admin,dc=example,dc=com"
bind_password = "admin"
}
2 changes: 2 additions & 0 deletions examples/resources/ldap_object/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$ export TF_LDAP_IMPORTER_PATH=a123456.tf
$ terraform import ldap_object.a123456 uid=a123456,ou=users,dc=example,dc=com
22 changes: 22 additions & 0 deletions examples/resources/ldap_object/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
resource "ldap_object" "users_example_com" {
dn = "ou=users,dc=example,dc=com"
object_classes = ["top", "organizationalUnit"]
}

resource "ldap_object" "a123456" {
dn = "uid=a123456,${ldap_object.users_example_com.dn}"
object_classes = ["inetOrgPerson", "posixAccount"]
attributes = [
{ sn = "Doe" },
{ givenName = "John" },
{ cn = "John Doe" },
{ displayName = "Mr. John K. Doe, esq." },
{ mail = "[email protected]" },
{ mail = "[email protected]" },
{ userPassword = "password" },
{ uidNumber = "1234" },
{ gidNumber = "1234" },
{ homeDirectory = "/home/jdoe" },
{ loginShell = "/bin/bash" }
]
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ go 1.14

require (
github.com/go-ldap/ldap/v3 v3.2.4
github.com/hashicorp/terraform-plugin-docs v0.4.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.5.0
github.com/mitchellh/gox v1.0.1
)
Loading

0 comments on commit 7b53ea1

Please sign in to comment.