Template for IBM Cloud Terraform provider projects.
Use this template to start developing Terraform provider support for new services using the openapi-sdkgen code generator.
Once your code is working, it should be integrated into the IBM Terraform Provider project.
Requirements
- Terraform 0.14.6+
- Go 1.13 (to build the provider plugin)
How to use this repository
This template repository is implemented as a
github template,
which makes it easy to create new projects from it.
To create a new Terraform provider project from this template, follow these instructions:
-
In your browser, open the link for this
template repository.
-
Click on the Use this template
button that appears next to the Clone or download
button.
-
In the next window:
- Select the
Owner
. This is the github id or organization where the new repository should be created
- Enter the respository name (e.g.
terraform-provider-test
)
- Click the
Create repository from template
button to create the new repository
After you have created your new Terraform provider project from the template, there are a few
small changes you need to make before you can use it.
- Find all occurrences of the template repository project name and replace with your project name.
cloudengineering/terraform-provider-template -> mkistler/terraform-provider-test
- Update the
HOSTNAME
and NAMESPACE
values in the Makefile
as appropriate. These will determine the "source" that
you must specify in Terraform provider scripts to use your new provider code.
Developing the Provider
To compile the provider, run make
.
make
To test the provider, run the Acceptance test suite.
You must provide an IBM Cloud API Key to the Acceptance tests in the IC_API_KEY
environment variable.
Then run the tests with make testacc
.
Note: Acceptance tests create real resources, and often cost money to run.
export IC_API_KEY=<your IBM Cloud API Key>
make testacc
To run a particular Acceptance test, pass variable TESTARGS
to make
:
make testacc TESTARGS="-run TestAccIBMNetworkVlan_Basic"
You can run tests against the internal "test.cloud.ibm.com" by setting environment variables for the appropriate service endpoints.
E.g.:
export IBMCLOUD_IAM_API_ENDPOINT=https://iam.test.cloud.ibm.com
export IBMCLOUD_RESOURCE_MANAGEMENT_API_ENDPOINT=https://resource-controller.test.cloud.ibm.com
The full list of service endpoint environment variables is available at
this link.
Using the provider
You can (and should) test your Terraform provider code with Terraform scripts that create and update the resources it supports.
You need to install your provider code into the local Terraform plugins directory, ~/.terraform.d/plugins
.
make install
will do this for you.
make install
In your main.tf
, configure the provider as follows:
variable "ibmcloud_api_key" {}
terraform {
required_providers {
ibm = {
source = "github.com/ibm-cloud/ibm"
version = "0.0.1"
}
}
}
provider "ibm" {
ibmcloud_api_key = var.ibmcloud_api_key
}
Note that the value of source
should be "HOSTNAME
/NAMESPACE
/ibm" using the variables from your Makefile.
Create a terraform.tfvars
file and specify your IBM Cloud API Key in that file:
ibmcloud_api_key = "<your IBM Cloud API Key>"
Then follow the standard steps for running Terraform scripts:
terraform init
terraform plan
terraform apply
See the official documentation for more details on using the IBM provider.