A simple example showing integration of the IBM Cloud provider for Terraform with Hashicorp CDK for Terraform.
For CDK for Terraform, you will need:
- Node.js and npm v16+.
- Terraform CLI (1.1+).
For the project, you will need:
- Python v3.7
- pipenv v2021.5.29 with
pip install --user pipenv
- Install CDK for Terraform
npm install --global cdktf-cli@latest
- Verify installation
cdktf help
The stack to be deployed is made of:
- one input variable
basename
-- a prefix to name the resources that will be created. - one resource group that will be named after this variable.
- one output variable containing the id of the resource group that was created.
The code for this stack is found in main.py. It was initialized with the command cdktf init --template=python --local
.
The IBM Cloud provider was added with the command cdktf provider add "IBM-Cloud/ibm@~> 1.44"
. This command modified the CDK configuration file (cdktf.json).
-
Retrieve the IBM Cloud provider and generate python constructs in the output directory
imports
:cdftk get
-
Set the environment variable
IBMCLOUD_API_KEY
export IBMCLOUD_API_KEY=...
-
Optionally set a prefix to name the resources that will be created. The example has a default value
cdktf-gs
.export TF_VAR_basename=uniqueprefix
-
Deploy the stack
cdktf deploy
Notice the
group_id
in the list of outputs.
-
Destroy the stack
cdktf destroy
See LICENSE for license information.