Terraform — Installing 3rd party Modules / Providers
Quick overview on how to install 3party modules & providers in terraform
Recently a project I’m working on called for adding computers in AD to existing OU groups. I couldn’t find an “official” provider for Terraform, but there was a community provider for this task found here :
- https://www.terraform.io/docs/providers/type/community-index.html
- https://github.com/GSLabDev/terraform-provider-ad
I fumbled around for quite a bit trying to “install” this provider. Terraform states in its documentation to place all 3rd party plugins in the following (Non-Windows) directory:~/.terraform.d/plugins.
Installing
Prerequisites:
- Install GO. (I’m on a Mac and used homebrew to install)
homebrew install go
- Add the following lines to your shell profile. I use z shell, and update the
~/.zshrc
# GOPATH
export GOPATH=$HOME/go
export GOBIN=$HOME/go/bin
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export PATH=$HOME/bin:/usr/local/bin:$GOPATH:$GOBIN:~/.local/bin:/usr/local/Cellar:~/Library/Python/3.7/bin/:$PATH
“Get” the Code
- With Go installed, now you can use the
go get
command on the repository. This will download and install the needed packages and create the executable needed for the terraform plugin directory. go get github.com/GSLabDev/terraform-provider-ad
- After running this, you now should have 3 directories in your [home]
~/go
directory: [bin
/pkg
/src
] - In this example, my executable was in the “bin” directory and was named “terraform-provider-ad”.
- Now you can simply copy that file/executable to the
.terraform.d/plugins
directory cp ~/go/bin/terraform-provider-ad ~/.terraform.d/plugins
- You can now run your
terraform init
and be good to go!
Failures
For those interested, the things I initially tried before discovering the go get
command include the following:
- Copying the repo of the provider to the plugin directory
- Copying to the
darwin_amd64
dir as stated by theterraform init
error output - Cloning the repo and running a
go build
It was the final step that finally clued me in that, what I needed to do, and the documentation stated (but I ignored since I’m stubborn) is to copy the “executable” to the plugins directory. This meant I needed an actual Provider executable. That’s when I realized I could use the go get
command. I didn’t state the background at the beginning, because I wanted the instructions to be clear at that the top. But just know, I typically do a lot of silly things before settling on what works.