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.
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
Use nix develop -c $SHELL
to enter the appropriate environment. You
need to have Flakes support for this to work.
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 outdated
$ yarn install --modules-folder ~/tmp/node_modules --ignore-scripts
$ yarn upgrade-interactive --modules-folder ~/tmp/node_modules --ignore-scripts --latest
Update nixpkgs:
$ nix flake update nixpkgs