This repository contains a Terraform CDK app for provisioning/managing VMs in vSphere.
Cloud Development Kit for Terraform allows you to define and provision infrastructure using a programming language you are comfortable with (i.e. TypeScript, Python, Java, C#, and Go (experimental)).
CDKTF synthesizes your infrastructure code into JSON configuration files that can be used by Terraform. It leverages concepts and libraries from the AWS Cloud Development Kit.
See CDK for Terraform for more details.
- Terraform CLI >= v1.0+
- Node.js >= v16+
- Terraform CDK:
npm install --global cdktf-cli@latest
- Run
npm installto install required packages - Run
cdktf get -l typescriptto get the vSphere provider - Update the configs.ts file with your vSphere username and password
- Run
cdktf deploy(Terraform will automatically configure alocalbackend unless a remote backend is configured. See Configure Remote Backend for more details.) - Look over plan and
approvechanges
Tests are located in the __tests__ directory main-test.ts file.
- Run
npm run testin the root directorycdktf-vsphere
- Run
cdktf destroy - Look over plan and
approvechanges
Provider bindings are generated by running cdktf get. See https://cdk.tf/provider-generation for more details.
- Add Provider to list of
terraformProvidersin cdktf.json - Run
cdktf get -l typescript
The following steps describe how to setup a Terraform Cloud remote backend for this app. We are currently only using TFc for state management. See CDKTF - Remote Backends for more details and other supported backends.
- Uncomment the
new RemoteBackendblock in stack.ts - Update the
hostnameandorganizationas needed - Update the configs.ts file with your Terraform Cloud workspace (
tfcloudWorkspace) - Run
cdktf synthto generate the Terraform configuration file - Run
cp terraform.cdktf-vsphere.tfstate cdktf.out/stacks/cdktf-vsphereto copy the Terraform state file into the output directory - Navigate to the output directory:
cd cdktf.out/stacks/cdktf-vsphere - Run
terraform init -migrate-stateto initialize the backend - Run
terraform state push -force terraform.cdktf-vsphere.tfstateto push the state to your Terraform Cloud workspace