[Infrastructure as Code (IaC)] Terraform LDAP Examples about using Terraform LDAP Provider to manage ldap objects
Terraform LDAP Examples
Examples about using Terraform LDAP Provider to manage ldap objects.
Github: https://github.com/CloudoLife/terraform-ldap-examples
Prerequsites
Your must have a LDAP server with bind account and password, and Terraform CLI have been installed.
LDAP Server with Bind Account and Password
Recommand use osixia/docker-openldap: A docker image to run OpenLDAP 🐳 - https://github.com/osixia/docker-openldap to run OpenLDAP server within container if you want to install the LDAP Server.
Thne, remember the admin account and bind password.
Terrraform and Terrafrom LDAP Provider
-
Use Infrastructure as Code to provision and manage any cloud, infrastructure, or service
-
CloudoLife/terraform-provider-ldap: LDAP provider for Terraform
The LDAP provider gives the ability to deploy and configure resources in a LDAP server.
Installation
First, install and config Terraform LDAP provider.
1 | ./install.sh |
It will go get github.com/CloudoLife/terraform-provider-ldap and create or append these content to ~/.terraformrc file.
1 | ~/.terraformrc |
Configuration
LDAP Provider Variables
First, Specify values for LDAP Provider variables within terraform.tfvars.
1 | ldap_host = "localhost" |
LDAP Object
Config LDAP objects within ./objects
1 | resource "ldap_object" "foo" { |
Run
Terraform Init
1 | terraform init |
It will download the Terraform LDAP Provider binary.
Terraform apply
1 | terraform apply |
It will dispaly the execute plan and wait for your make yes or no.
Then yes to create ldap objects.
Import
Import and create .tf file by run ./import.sh command.
1 | ./import.sh uid=foo,dc=example,dc=com |
It will import LDAP object(uid=foo,dc=example,dc=com) to Terraform State(terraform.tfstate) and auto create the ldap_object.foo.tf file.
You can continue to maintain that file and run terraform apply command to manage the exist LDAP objects without copying & pasting from Terraform State(terraform.tfstate).
Inspire
Inspired by Pryz/terraform-provider-ldap: LDAP provider for Terraform.
Reference
[2] CloudoLife/terraform-provider-ldap: LDAP provider for Terraform
[2] Terraform by HashiCorp - https://www.terraform.io/
[3] Pryz/terraform-provider-ldap: LDAP provider for Terraform
[4] osixia/docker-openldap: A docker image to run OpenLDAP 🐳 - https://github.com/osixia/docker-openldap