Dual-write ENC data into encapi alongside Cobbler #39
Reference in New Issue
Block a user
Delete Branch "benvin/encapi-seed"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
Seed encapi so the k8s puppetserver ENC can cut over from Cobbler. encapi's DB is currently empty; nothing can point Puppet at it until the roles/statuses/nodes exist. This change makes terraform-incus dual-write the ENC data into encapi alongside the existing Cobbler/PuppetCA/PuppetDB resources. No Cobbler removal happens here — those resources are left fully intact until a later cutover PR.
Changes
config/encapileaf backed by a newmodules/encapithat seeds encapi from YAML:statuses.yaml— 3 statuses (production,develop,testing). All 143 nodes currently reportcatalog_environment=develop;productionis seeded because the instance module pins VMs there (matchingpuppetca_certificate),testingis the implicit/transient one.roles.yaml— 51 distinct role classes: everycobbler_mgmt_classes[0]acrossconfig/instances/*/config.yaml(48) plus the 3 roles run by the physicalprodnxsr*nodes (roles::infra::incus::node,roles::infra::k8s::compute,roles::infra::k8s::control).nodes.yaml— encapi_node assignments for the 13prodnxsr*bare-metal nodes (certname → role from the PuppetDBenc_rolefact,environment: developto match their currentcatalog_environment). These hosts are not managed by the instance module, so they are seeded explicitly here.modules/instanceto also create anencapi_nodefor every VM: certname<name>.<cobbler_domain>, rolevar.cobbler_mgmt_classes[0], environmentproduction(matches whatcobbler_system/puppetca_certificateuse today; overridable via newencapi_environmentvar).cobbler_system/puppetca_certificate/puppetdb_nodeare unchanged.encapiprovider (git.unkin.net/unkin/encapiv0.1.0) intoconfig/root.hcl's generatedrequired_providersand both moduleproviders.tffiles.ENCAPI_WRITE_TOKENinto terraform viaMakefilevault_env(the provider reads the bearer token straight from that env var).Apply order (important — FK ordering)
encapi nodes FK-require their role and status to already exist. Apply
config/encapibefore the instance leaves. Within a singleterragrunt run --all apply(parallelism 2) this is not automatically ordered — the instance leaves have no terragruntdependencyon the encapi leaf (adding 130 of them is noisy and the encapi leaf has no outputs the instances consume). Recommended: runterragrunt applyinconfig/encapifirst, or add a one-off ordering for the initial seed. Themodules/encapiencapi_noderesources alreadydepends_onthe roles/statuses within that leaf.Prerequisites (orchestrator / follow-up PRs)
TERRAFORM_INCUS_VAULT_ROLEIDapprole, whose policy today readskv/service/puppet/*andkv/data/service/terraform/incus. It does not grant read onkv/kubernetes/namespace/encapi/default/environment(whereENCAPI_WRITE_TOKENlives). A terraform-vault change is required to addreadonkv/data/kubernetes/namespace/encapi/default/environment(and metadata) to that approle's policy, or themake applystep will fail resolving the token. Not fixed in this PR.git.unkin.net/unkin/encapiresolves via the ArtifactAPI Terraform registry (artifactapi.k8s.syd1.au.unkin.net,/terraform/v1/providers/), not viagit.unkin.netdirectly. CI's terraform needs a CLI config (host "git.unkin.net" { services = { "providers.v1" = "https://artifactapi.k8s.syd1.au.unkin.net/terraform/v1/providers/" } }) or a network mirror soterraform initcan fetch it. Localterraform initagainstgit.unkin.netfails with "does not offer a Terraform provider registry" without this.Validation done
terraform fmtclean on both modules;terragrunt hcl fmtclean on the leaf/root.modules/encapiterraform init -backend=false+terraform validate= Success (against a locally built v0.1.0 provider via filesystem mirror). This exercises the sameencapi_status/encapi_role/encapi_nodeschemas and provider block the instance module uses.modules/instancecannotvalidatestandalone (its../../../../../../modules/*relative sources only resolve from a 6-deep leaf) — pre-existing, unaffected by this change.Closing: superseded by the new dedicated
terragrunt-encrepo (all encapi ENC data managed there; no changes to terraform-incus). Replacement PRs incoming.Pull request closed