/cdktf-take1

Musing around CDKTF

Primary LanguageTypeScript

Musings around CDKTF

This is my first tentative to use CDKTF to manage my personal infrastructure. This is an exploration to let me become more familiar with it. Servers are then managed using NixOps. Check my nixops-take1 repository for this part.

Interaction with NixOps

When there is a change, the stack output should be exported to NixOps:

$ cd cdktf.out/stacks/cdktf-take1
$ terraform output -json > ~-automation/nixops-take1/cdktf.json

Various commands

Shell

Use nix develop -c $SHELL to enter the appropriate environment. You need to have Flakes support for this to work.

CDKTF

These are the commands specific to CDKTF.

$ cdktf synth
$ cdktf diff
$ cdktf deploy

Alternatively, one may only use cdktf synth, then switch to Terraform commands (they are far more flexible):

$ cd cdktf.out/stacks/cdktf-take1
$ terraform plan --out plan
$ terraform plan --out plan --refresh=false
$ terraform apply plan
$ terraform output -json > ~-automation/nixops-take1/cdktf.json

Notably, one can import resources this way:

$ terraform state list
$ terraform show --json plan | jq -r '.planned_values.root_module.resources[].address'
$ terraform import aws_cloudfront_distribution.cdktftake1_mediabernatch_1FD37B2F E1KREAZ6F4767X

To get the resources from Pulumi, one can use:

$ cat .pulumi/stacks/dev.json | jq -r '.checkpoint.latest.resources[] | (.urn + " → " + .id)' | grep rdns

Yarn (for JavaScript dependencies)

$ yarn outdated
$ yarn install --modules-folder ~/tmp/node_modules --ignore-scripts
$ yarn upgrade-interactive --modules-folder ~/tmp/node_modules --ignore-scripts --latest

Nix

Update nixpkgs:

$ nix flake update nixpkgs