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 install
to install required packages - Run
cdktf get -l typescript
to get the vSphere provider - Update the configs.ts file with your vSphere username and password
- Run
cdktf deploy
(Terraform will automatically configure alocal
backend unless a remote backend is configured. See Configure Remote Backend for more details.) - Look over plan and
approve
changes
Tests are located in the __tests__
directory main-test.ts file.
- Run
npm run test
in the root directorycdktf-vsphere
- Run
cdktf destroy
- Look over plan and
approve
changes
Provider bindings are generated by running cdktf get. See https://cdk.tf/provider-generation for more details.
- Add Provider to list of
terraformProviders
in 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 RemoteBackend
block in stack.ts - Update the
hostname
andorganization
as needed - Update the configs.ts file with your Terraform Cloud workspace (
tfcloudWorkspace
) - Run
cdktf synth
to generate the Terraform configuration file - Run
cp terraform.cdktf-vsphere.tfstate cdktf.out/stacks/cdktf-vsphere
to copy the Terraform state file into the output directory - Navigate to the output directory:
cd cdktf.out/stacks/cdktf-vsphere
- Run
terraform init -migrate-state
to initialize the backend - Run
terraform state push -force terraform.cdktf-vsphere.tfstate
to push the state to your Terraform Cloud workspace