This is the official Control Plane Terraform provider. Terraform usage and reference documentation is available on the Terraform Registry.
Install terraform-provider locally.
- From a path under '${GOPATH}', clone the provider code:
git clone https://github.com/controlplane-com/terraform-provider-cpln.git
- cd into the cloned direction and install using make (Default OS Architecture is linux_amd64):
cd terraform-provider
make install
For macOS (Apple Silicion):
make install OS_ARCH=darwin_arm64
For macOS:
make install OS_ARCH=darwin_amd64
The provider is installed under the ~/.terraform.d/plugins/ directory.
Considering the provider is installed at path below after running the make install command:
/Users/<username>/.terraform.d/plugins/controlplane.com/com/cpln/1.0.10/darwin_arm64
-
Add a
.terraform.rcfile on root with the contents belowprovider_installation { filesystem_mirror { path = "/Users/<username>/.terraform.d/plugins" } direct { exclude = ["controlplane.com/*/*"] } }
-
In your Terraform config (
main.tf), set:terraform { required_providers { cpln = { source = "controlplane.com/com/cpln" version = "<version>" } } }
-
Run
terraform init. You should see the warning below if it succeeded:Warning: Incomplete lock file information for providers Due to your customized provider installation methods, Terraform was forced to calculate lock file checksums locally for the following providers: - controlplane.com/com/cpln
When debugging, create the file at .vscode/launch.json by copying and editing it from the launch.json.example file.
See the HCL examples within the /examples directory.
# 1. Log in via CLI
cpln login
# (For test environment)
cpln profile update default --login --endpoint https://api.test.cpln.io
# 2. Initialize Terraform
terraform init
# 3. Apply a sample configuration
terraform apply -var="org=<YOUR_ORG>"
# 4. When you’re done:
terraform destroy -var="org=<YOUR_ORG>"For full examples, see the examples/ directory.
- Unit Tests:
make test - Acceptance Tests:
make testacc
Make sure to configure a valid org in internal/provider/config.go before running acceptance tests.
- Creating a new service account
a) Create service account:
'cpln serviceaccount create --name <service_account_name> --org <organization_name>'
b) Edit group:
'cpln group edit superusers --org <organization_name>'
Using the editor, add the service account to the memberLinks element using the format:
'/org/<organziation_name>/serviceaccount/<service_account_name>'
c) Add key to service account:
'cpln serviceaccount add-key <service_account_name> --org <organization_name> --description <key_description>'
d) Create a profile with the token output from step c:
'cpln profile create <profile_name> --token <token>'
- To obtain a valid access token via the Control Plane CLI:
a) Using the default profile:
'cpln profile token'
OR
'cpln profile token default'
b) Using a created profile:
'cpln profile token <profile_name>'
- Misc WSL Commands
a) Allow WSL network through Windows Firewall:
New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow
- Run the script
cpln_docs.shwithin the /scripts directory. - Copy the
terraform_reference.mdxfile to the directory/pages/terraformin the documentation project.
- Run
make release - Plugins will be in /bin directory
- Use commands below to compress (update version)
macOS
tar -cvzf terraform-provider-cpln_1.0.0_darwin_amd64.tgz terraform-provider-cpln_1.0.0_darwin_amd64
macOS (Apple Silicon)
tar -cvzf terraform-provider-cpln_1.0.0_darwin_amd64.tgz terraform-provider-cpln_1.0.0_darwin_arm64
Linux
tar -cvzf terraform-provider-cpln_1.0.0_linux_amd64.tgz terraform-provider-cpln_1.0.0_linux_amd64
Windows
tar -cvzf terraform-provider-cpln_1.0.0_windows_amd64.zip terraform-provider-cpln_1.0.0_windows_amd64.exe
- https://www.terraform.io/registry/providers/publishing
- git tag vX.X.X
- git push origin vX.X.X
- Needed to add CGO_ENABLED=0 for linux build when running within an alpine image. See: Mastercard/terraform-provider-restapi#65
- CLI Config File: https://www.terraform.io/docs/cli/config/config-file.html
When adding new resources or data sources:
- Update the API client schema in
internal/provider/client/<item>.go. - Define or adjust the Terraform schema in:
internal/provider/resource_<item>.go(resources)internal/provider/data_source_<item>.go(data sources)
- Update the CRUD/context functions under each resource.
- Add or update tests in
*_test.go. - Regenerate the reference docs via:
cd scripts ./cpln_docs.sh # then copy terraform_reference.mdx into your docs site
- Update resource / data source examples.
All version history and release notes have been moved to CHANGELOG.md.