| description | Architectural context and guidelines for the downstream cluster example. | |
|---|---|---|
| globs |
|
When you are asked to troubleshoot, refactor, or add features to the downstream example, you MUST use your file-reading tools to read the following files into context before proceeding:
examples/downstream/main.tf(to understand the current node configs and provider setups)examples/downstream/modules/deploy/variables.tf(to understand the inputs expected by the deployment module)examples/downstream/modules/downstream_securitygroups/variables.tf(to understand the inputs expected by the security group module)examples/downstream/modules/downstream/variables.tf(to understand the inputs expected by the downstream module)examples/downstream/downstream/variables.tf(to understand the inputs expected by the downstream module deployment)
When modifying files in the examples/downstream directory, strictly adhere to the following architectural guidelines, developer paradigms, and operational flows.
- Local Modules (LMod): The subdirectories (
modules/) are not independent; they act like function calls integral to the orchestration. Never nest Local Modules inside one another. - Highly Opinionated Selectors: Use the
configslocal block in the rootmain.tfas a feature selector. Do not expose all Kubernetes parameters to the user; instead, rely on selecting a predefined architecture (likeprod-node-configorsplit-role-node-config). - All Variables in Locals: Map variables in
main.tfimmediately to alocalsblock. Resources must only reference theselocalsto isolate variable transformations.
When refactoring or adding features, ensure you respect and maintain the established execution flow:
- Upstream Deployment: The root
main.tftriggers the deployment of the parent module, provisioning an RKE2 cluster and installing Rancher. - Rancher Authentication:
rancher2_bootstrapgrabs the admin token and configures the defaultrancher2provider once the UI is available. - Downstream Security:
modules/downstream_securitygroupsmaps network rules allowing the authenticated Rancher server to communicate with future downstream nodes. - Downstream Networking:
modules/downstreamestablishes a private subnet and a NAT gateway for isolated node provisioning. - Downstream Provisioning:
modules/downstreamtalks to the Rancher API to create Machine Configs (EC2 templates) and a new RKE2 Cluster definition. - State Syncing:
rancher2_cluster_syncblocks Terraform execution until the newly provisioned downstream cluster achieves an active state.
- Keep logic focused on setting up the upstream cluster, provider authentication, and delegating to local modules.
- Outputs should output sensitive connection and state data generated from the upstream cluster (kubeconfig, tokens, etc).
- Exclusively manage network boundaries and access rules (ingress/egress) for the downstream cluster.
- Ensure traffic is allowed between the downstream cluster, the load balancer, and the upstream Rancher cluster's security group.
- Manage downstream networking (subnets/Route Tables/NAT) to ensure downstream nodes are isolated from the public internet.
- Dynamically provision Machine Configs and map node roles (control plane, etcd, worker).
- Use
terraform_dataprovisioners to execute credential patching viaaddKeyToAmazonConfig.sh. - Do not expose direct SSH outputs since nodes reside in a private subnet.