From 7b53ea17686184f7a7e1b5dbd879f718154b9cc9 Mon Sep 17 00:00:00 2001 From: Hirotake Kobayashi Date: Thu, 1 Apr 2021 17:50:12 +0900 Subject: [PATCH] refactoring (#11) * 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 --- .editorconfig | 13 ++++ .gitignore | 57 ++++++++++-------- .goreleaser.yml | 43 +++++++++++++ .vscode/launch.json | 33 ++++++++++ Makefile | 18 ++---- docs/index.md | 47 +++++++++++++++ docs/resources/object.md | 60 +++++++++++++++++++ examples/provider/provider.tf | 15 +++++ examples/resources/ldap_object/import.sh | 2 + examples/resources/ldap_object/resource.tf | 22 +++++++ go.mod | 2 +- go.sum | 40 +++++++++++-- internal/helper/client/config.go | 12 ++++ config.go => internal/helper/client/ldap.go | 20 ++----- internal/helper/hashcode/hashcode.go | 20 +++++++ set.go => internal/helper/set/set.go | 6 +- .../helper/set/set_test.go | 4 +- provider.go => internal/provider/provider.go | 7 ++- .../provider/provider_test.go | 2 +- .../provider/resource_ldap_object.go | 42 ++++--------- .../provider/resource_ldap_object_test.go | 2 +- main.go | 27 ++++++++- templates/index.md.tmpl | 16 +++++ tests/docker-compose.yml | 2 +- tests/main.tf | 10 +++- tools.go | 7 --- tools/tools.go | 7 +++ 27 files changed, 426 insertions(+), 110 deletions(-) create mode 100644 .editorconfig create mode 100644 .goreleaser.yml create mode 100644 .vscode/launch.json create mode 100644 docs/index.md create mode 100644 docs/resources/object.md create mode 100644 examples/provider/provider.tf create mode 100644 examples/resources/ldap_object/import.sh create mode 100644 examples/resources/ldap_object/resource.tf create mode 100644 internal/helper/client/config.go rename config.go => internal/helper/client/ldap.go (65%) create mode 100644 internal/helper/hashcode/hashcode.go rename set.go => internal/helper/set/set.go (97%) rename set_test.go => internal/helper/set/set_test.go (98%) rename provider.go => internal/provider/provider.go (93%) rename provider_test.go => internal/provider/provider_test.go (98%) rename resource_ldap_object.go => internal/provider/resource_ldap_object.go (96%) rename resource_ldap_object_test.go => internal/provider/resource_ldap_object_test.go (99%) create mode 100644 templates/index.md.tmpl delete mode 100644 tools.go create mode 100644 tools/tools.go diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f04a189 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.gitignore b/.gitignore index 0268926..fd3ad8e 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..880aa35 --- /dev/null +++ b/.goreleaser.yml @@ -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 diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..9f07c45 --- /dev/null +++ b/.vscode/launch.json @@ -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", + ], + } + ] +} diff --git a/Makefile b/Makefile index f83027c..50befc4 100644 --- a/Makefile +++ b/Makefile @@ -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 ./... diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..3b718d7 --- /dev/null +++ b/docs/index.md @@ -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 + +### 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). diff --git a/docs/resources/object.md b/docs/resources/object.md new file mode 100644 index 0000000..ff063ff --- /dev/null +++ b/docs/resources/object.md @@ -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 = "john.doe@example.com" }, + { mail = "jdoe@example.com" }, + { userPassword = "password" }, + { uidNumber = "1234" }, + { gidNumber = "1234" }, + { homeDirectory = "/home/jdoe" }, + { loginShell = "/bin/bash" } + ] +} +``` + + +## 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 +``` diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf new file mode 100644 index 0000000..971ea4b --- /dev/null +++ b/examples/provider/provider.tf @@ -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" +} diff --git a/examples/resources/ldap_object/import.sh b/examples/resources/ldap_object/import.sh new file mode 100644 index 0000000..8e799f6 --- /dev/null +++ b/examples/resources/ldap_object/import.sh @@ -0,0 +1,2 @@ +$ export TF_LDAP_IMPORTER_PATH=a123456.tf +$ terraform import ldap_object.a123456 uid=a123456,ou=users,dc=example,dc=com diff --git a/examples/resources/ldap_object/resource.tf b/examples/resources/ldap_object/resource.tf new file mode 100644 index 0000000..977a854 --- /dev/null +++ b/examples/resources/ldap_object/resource.tf @@ -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 = "john.doe@example.com" }, + { mail = "jdoe@example.com" }, + { userPassword = "password" }, + { uidNumber = "1234" }, + { gidNumber = "1234" }, + { homeDirectory = "/home/jdoe" }, + { loginShell = "/bin/bash" } + ] +} diff --git a/go.mod b/go.mod index 7c9b94a..2da0f47 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 07c381a..72e08de 100644 --- a/go.sum +++ b/go.sum @@ -37,6 +37,12 @@ github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c h1:/IBSNwUN8+eKzU github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg= +github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= +github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= +github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= +github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60= +github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= 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= @@ -53,7 +59,9 @@ github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0 h1:MzVXffFU github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2wFoYVvnCs0= github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk= +github.com/apparentlymart/go-textseg/v12 v12.0.0 h1:bNEQyAGak9tojivJNkoqWErVCQbjdL7GzRt3F8NvfJ0= github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= +github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 h1:BUAU3CGlLvorLI26FmByPp2eC2qla6E1Tw+scpcg/to= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= @@ -155,6 +163,8 @@ github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= @@ -185,7 +195,6 @@ github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoD github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI= github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= @@ -196,10 +205,13 @@ github.com/hashicorp/hcl/v2 v2.3.0 h1:iRly8YaMwTBAKhn1Ybk7VSdzbnopghktCD031P8ggU github.com/hashicorp/hcl/v2 v2.3.0/go.mod h1:d+FwDBbOLvpAM3Z6J7gPj/VoAGkNe/gm352ZhjJ/Zv8= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/terraform-exec v0.12.0/go.mod h1:SGhto91bVRlgXQWcJ5znSz+29UZIa8kpBbkGwQ+g9E8= github.com/hashicorp/terraform-exec v0.13.0 h1:1Pth+pdWJAufJuWWjaVOVNEkoRTOjGn3hQpAqj4aPdg= github.com/hashicorp/terraform-exec v0.13.0/go.mod h1:SGhto91bVRlgXQWcJ5znSz+29UZIa8kpBbkGwQ+g9E8= github.com/hashicorp/terraform-json v0.8.0 h1:XObQ3PgqU52YLQKEaJ08QtUshAfN3yu4u8ebSW0vztc= github.com/hashicorp/terraform-json v0.8.0/go.mod h1:3defM4kkMfttwiE7VakJDwCd4R+umhSQnvJwORXbprE= +github.com/hashicorp/terraform-plugin-docs v0.4.0 h1:xJIXsMzBFwBvC1zcjoNz743GL2tNEfYFFU9+Hjp4Uek= +github.com/hashicorp/terraform-plugin-docs v0.4.0/go.mod h1:fKj/V3t45tiXpSlUms/0G4OrBayyWpbUJ4WtLjBkINU= github.com/hashicorp/terraform-plugin-go v0.2.1 h1:EW/R8bB2Zbkjmugzsy1d27yS8/0454b3MtYHkzOknqA= github.com/hashicorp/terraform-plugin-go v0.2.1/go.mod h1:10V6F3taeDWVAoLlkmArKttR3IULlRWFAGtQIQTIDr4= github.com/hashicorp/terraform-plugin-sdk/v2 v2.5.0 h1:4EHNOAjwiYCeBxY16rt2KwyRNNVsCaVO3kWBbiXfYM0= @@ -207,9 +219,13 @@ github.com/hashicorp/terraform-plugin-sdk/v2 v2.5.0/go.mod h1:z+cMZ0iswzZOahBJ3X github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= +github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw= +github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg= github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA= +github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= @@ -237,13 +253,19 @@ github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= +github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10= github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mitchellh/cli v1.1.1/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= +github.com/mitchellh/cli v1.1.2 h1:PvH+lL2B7IQ101xQL63Of8yFS2y+aDlsFcsqNc+u/Kw= +github.com/mitchellh/cli v1.1.2/go.mod h1:6iaV0fGdElS6dPBx0EApTxHrcWvmJphyh2n8YBLPPZ4= github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -257,10 +279,6 @@ github.com/mitchellh/go-testing-interface v1.0.4/go.mod h1:kRemZodwjscx+RGhAo8eI github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= -github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI= -github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4= -github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY= -github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= @@ -277,9 +295,12 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/posener/complete v1.1.1 h1:ccV59UEOTzVDnDUEFdT95ZzHVZ+5+158q8+SJb2QV5w= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= +github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= @@ -297,6 +318,8 @@ github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oW github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= +github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= +github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -305,6 +328,8 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= github.com/zclconf/go-cty v1.2.1 h1:vGMsygfmeCl4Xb6OA5U5XVAaQZ69FvoG7X2jUtQujb8= github.com/zclconf/go-cty v1.2.1/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= +github.com/zclconf/go-cty v1.7.1 h1:AvsC01GMhMLFL8CgEYdHGM+yLnnDOwhPAYcgTkeF0Gw= +github.com/zclconf/go-cty v1.7.1/go.mod h1:VDR4+I79ubFBGm1uJac1226K5yANQFHeauxPBoP54+o= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0 h1:C9hSCOW830chIVkdja34wa6Ky+IzWllkUinR+BtRZd4= @@ -323,6 +348,8 @@ golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM= +golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -416,6 +443,7 @@ golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -573,6 +601,8 @@ gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRN gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/internal/helper/client/config.go b/internal/helper/client/config.go new file mode 100644 index 0000000..65890bf --- /dev/null +++ b/internal/helper/client/config.go @@ -0,0 +1,12 @@ +package client + +type Config struct { + LDAPHost string + LDAPPort int + BindUser string + BindPassword string + + StartTLS bool + TLS bool + TLSInsecure bool +} diff --git a/config.go b/internal/helper/client/ldap.go similarity index 65% rename from config.go rename to internal/helper/client/ldap.go index e45f8af..e809bf1 100644 --- a/config.go +++ b/internal/helper/client/ldap.go @@ -1,4 +1,4 @@ -package main +package client import ( "crypto/tls" @@ -7,20 +7,8 @@ import ( "github.com/go-ldap/ldap/v3" ) -// Config is the set of parameters needed to configure the LDAP provider. -type Config struct { - LDAPHost string - LDAPPort int - BindUser string - BindPassword string - - StartTLS bool - TLS bool - TLSInsecure bool -} - -func (c *Config) initiateAndBind() (*ldap.Conn, error) { - conn, err := c.dial() +func DialAndBind(c *Config) (*ldap.Conn, error) { + conn, err := dial(c) if err != nil { return nil, err } @@ -36,7 +24,7 @@ func (c *Config) initiateAndBind() (*ldap.Conn, error) { return conn, nil } -func (c *Config) dial() (*ldap.Conn, error) { +func dial(c *Config) (*ldap.Conn, error) { uri := fmt.Sprintf("%s:%d", c.LDAPHost, c.LDAPPort) if c.TLS { diff --git a/internal/helper/hashcode/hashcode.go b/internal/helper/hashcode/hashcode.go new file mode 100644 index 0000000..112539d --- /dev/null +++ b/internal/helper/hashcode/hashcode.go @@ -0,0 +1,20 @@ +package hashcode + +import "hash/crc32" + +// String hashes a string to a unique hashcode. +// +// crc32 returns a uint32, but for our use we need +// and non negative integer. Here we cast to an integer +// and invert it if the result is negative. +func String(s string) int { + v := int(crc32.ChecksumIEEE([]byte(s))) + if v >= 0 { + return v + } + if -v >= 0 { + return -v + } + // v == MinInt + return 0 +} diff --git a/set.go b/internal/helper/set/set.go similarity index 97% rename from set.go rename to internal/helper/set/set.go index bc2e6d6..a32cd31 100644 --- a/set.go +++ b/internal/helper/set/set.go @@ -1,4 +1,4 @@ -package main +package set import ( "bytes" @@ -11,8 +11,8 @@ type Set struct { data map[string]struct{} } -// NewSet creates a new string set. -func NewSet(values ...string) *Set { +// New creates a new string set. +func New(values ...string) *Set { set := &Set{ data: map[string]struct{}{}, } diff --git a/set_test.go b/internal/helper/set/set_test.go similarity index 98% rename from set_test.go rename to internal/helper/set/set_test.go index 7105aff..61696c0 100644 --- a/set_test.go +++ b/internal/helper/set/set_test.go @@ -1,4 +1,4 @@ -package main +package set import "testing" @@ -14,7 +14,7 @@ func setup() (*Set, *Set) { s1.Add("e") s1.Add("f") - s2 := NewSet() + s2 := New() s2.Add("a") s2.Add("b") s2.Add("c") diff --git a/provider.go b/internal/provider/provider.go similarity index 93% rename from provider.go rename to internal/provider/provider.go index 6de64e5..67445cd 100644 --- a/provider.go +++ b/internal/provider/provider.go @@ -1,6 +1,7 @@ -package main +package provider import ( + "github.com/elastic-infra/terraform-provider-ldap/internal/helper/client" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -67,7 +68,7 @@ func Provider() *schema.Provider { } func configureProvider(d *schema.ResourceData) (interface{}, error) { - config := Config{ + config := &client.Config{ LDAPHost: d.Get("ldap_host").(string), LDAPPort: d.Get("ldap_port").(int), BindUser: d.Get("bind_user").(string), @@ -77,7 +78,7 @@ func configureProvider(d *schema.ResourceData) (interface{}, error) { TLSInsecure: d.Get("tls_insecure").(bool), } - connection, err := config.initiateAndBind() + connection, err := client.DialAndBind(config) if err != nil { return nil, err } diff --git a/provider_test.go b/internal/provider/provider_test.go similarity index 98% rename from provider_test.go rename to internal/provider/provider_test.go index d6465a4..afeb99e 100644 --- a/provider_test.go +++ b/internal/provider/provider_test.go @@ -1,4 +1,4 @@ -package main +package provider import ( "os" diff --git a/resource_ldap_object.go b/internal/provider/resource_ldap_object.go similarity index 96% rename from resource_ldap_object.go rename to internal/provider/resource_ldap_object.go index fe4ae61..ff7302c 100644 --- a/resource_ldap_object.go +++ b/internal/provider/resource_ldap_object.go @@ -1,15 +1,14 @@ -package main +package provider import ( "bytes" - "hash/crc32" - "log" - "fmt" - "strings" - + "log" "os" + "strings" + "github.com/elastic-infra/terraform-provider-ldap/internal/helper/hashcode" + "github.com/elastic-infra/terraform-provider-ldap/internal/helper/set" "github.com/go-ldap/ldap/v3" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -59,6 +58,8 @@ func resourceLDAPObject() *schema.Resource { Optional: true, }, }, + + Description: "Provides a LDAP Object.", } } @@ -380,7 +381,7 @@ func attributeHash(v interface{}) int { // In case of calculated fields, v might be nil. if !ok { - return String("nil") + return hashcode.String("nil") } var buffer bytes.Buffer @@ -390,27 +391,10 @@ func attributeHash(v interface{}) int { } buffer.WriteRune('}') text := buffer.String() - hash := String(text) + hash := hashcode.String(text) return hash } -// String hashes a string to a unique hashcode. -// -// crc32 returns a uint32, but for our use we need -// and non negative integer. Here we cast to an integer -// and invert it if the result is negative. -func String(s string) int { - v := int(crc32.ChecksumIEEE([]byte(s))) - if v >= 0 { - return v - } - if -v >= 0 { - return -v - } - // v == MinInt - return 0 -} - func printAttributes(prefix string, attributes interface{}) string { var buffer bytes.Buffer buffer.WriteString(fmt.Sprintf("%s: {\n", prefix)) @@ -427,28 +411,28 @@ func printAttributes(prefix string, attributes interface{}) string { func computeDeltas(os, ns *schema.Set) (added, changed, removed []ldap.PartialAttribute) { - rk := NewSet() // names of removed attributes + rk := set.New() // names of removed attributes for _, v := range os.Difference(ns).List() { for k := range v.(map[string]interface{}) { rk.Add(k) } } - ak := NewSet() // names of added attributes + ak := set.New() // names of added attributes for _, v := range ns.Difference(os).List() { for k := range v.(map[string]interface{}) { ak.Add(k) } } - kk := NewSet() // names of kept attributes + kk := set.New() // names of kept attributes for _, v := range ns.Intersection(os).List() { for k := range v.(map[string]interface{}) { kk.Add(k) } } - ck := NewSet() // names of changed attributes + ck := set.New() // names of changed attributes // loop over remove attributes' names for _, k := range rk.List() { diff --git a/resource_ldap_object_test.go b/internal/provider/resource_ldap_object_test.go similarity index 99% rename from resource_ldap_object_test.go rename to internal/provider/resource_ldap_object_test.go index bcbb23c..546fbc3 100644 --- a/resource_ldap_object_test.go +++ b/internal/provider/resource_ldap_object_test.go @@ -1,4 +1,4 @@ -package main +package provider import ( "errors" diff --git a/main.go b/main.go index be36e28..38c5ffb 100644 --- a/main.go +++ b/main.go @@ -1,11 +1,32 @@ package main import ( + "context" + "flag" + "log" + + "github.com/elastic-infra/terraform-provider-ldap/internal/provider" "github.com/hashicorp/terraform-plugin-sdk/v2/plugin" ) +//go:generate terraform fmt -recursive ./examples/ +//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs + func main() { - plugin.Serve(&plugin.ServeOpts{ - ProviderFunc: Provider, - }) + var debugMode bool + + flag.BoolVar(&debugMode, "debug", false, "set to true to run the provider with support for debuggers like delve") + flag.Parse() + + opts := &plugin.ServeOpts{ProviderFunc: provider.Provider} + + if debugMode { + err := plugin.Debug(context.Background(), "registry.terraform.io/elastic-infra/terraform-provider-ldap", opts) + if err != nil { + log.Fatal(err.Error()) + } + return + } + + plugin.Serve(opts) } diff --git a/templates/index.md.tmpl b/templates/index.md.tmpl new file mode 100644 index 0000000..34feffa --- /dev/null +++ b/templates/index.md.tmpl @@ -0,0 +1,16 @@ +--- +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 + +{{tffile "examples/provider/provider.tf"}} + +{{ .SchemaMarkdown | trimspace }} diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 75172cc..80590dc 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -19,4 +19,4 @@ services: PHPLDAPADMIN_LDAP_HOSTS: "openldap" image: osixia/phpldapadmin:latest ports: - - "6443:443" \ No newline at end of file + - "8443:443" diff --git a/tests/main.tf b/tests/main.tf index ca453cc..c1496fc 100644 --- a/tests/main.tf +++ b/tests/main.tf @@ -1,10 +1,18 @@ /* * LDAP is the OpenLDAP server. */ +terraform { + required_providers { + ldap = { + source = "elastic-infra/ldap" + version = "~> 2.0" + } + } +} + provider "ldap" { ldap_host = "localhost" ldap_port = 389 - use_tls = false bind_user = "cn=admin,dc=example,dc=com" bind_password = "admin" } diff --git a/tools.go b/tools.go deleted file mode 100644 index 5101258..0000000 --- a/tools.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build tools - -package tools - -import ( - _ "github.com/mitchellh/gox" -) diff --git a/tools/tools.go b/tools/tools.go new file mode 100644 index 0000000..2735de6 --- /dev/null +++ b/tools/tools.go @@ -0,0 +1,7 @@ +// +build tools + +package tools + +import ( + _ "github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs" +)