Skip to content

Commit 6f9162b

Browse files
authored
fix: update to new module versions (#157)
Signed-off-by: matttrach <matt.trachier@suse.com>
1 parent 64ffe21 commit 6f9162b

55 files changed

Lines changed: 1659 additions & 1479 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/rules/downstream.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
description: Architectural context and guidelines for the downstream cluster example.
3+
globs: ["examples/downstream/**/*"]
4+
---
5+
# Downstream Example Rules
6+
7+
## Context Loading
8+
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:
9+
- `examples/downstream/main.tf` (to understand the current node configs and provider setups)
10+
- `examples/downstream/modules/deploy/variables.tf` (to understand the inputs expected by the deployment module)
11+
- `examples/downstream/modules/downstream_securitygroups/variables.tf` (to understand the inputs expected by the security group module)
12+
- `examples/downstream/modules/downstream/variables.tf` (to understand the inputs expected by the downstream module)
13+
- `examples/downstream/downstream/variables.tf` (to understand the inputs expected by the downstream module deployment)
14+
15+
When modifying files in the `examples/downstream` directory, strictly adhere to the following architectural guidelines, developer paradigms, and operational flows.
16+
17+
## Developer Paradigms
18+
- **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.**
19+
- **Highly Opinionated Selectors**: Use the `configs` local block in the root `main.tf` as a feature selector. Do not expose all Kubernetes parameters to the user; instead, rely on selecting a predefined architecture (like `prod-node-config` or `split-role-node-config`).
20+
- **All Variables in Locals**: Map variables in `main.tf` immediately to a `locals` block. Resources must only reference these `locals` to isolate variable transformations.
21+
22+
## Execution Flow
23+
When refactoring or adding features, ensure you respect and maintain the established execution flow:
24+
1. **Upstream Deployment**: The root `main.tf` triggers the deployment of the parent module, provisioning an RKE2 cluster and installing Rancher.
25+
2. **Rancher Authentication**: `rancher2_bootstrap` grabs the admin token and configures the default `rancher2` provider once the UI is available.
26+
3. **Downstream Security**: `modules/downstream_securitygroups` maps network rules allowing the authenticated Rancher server to communicate with future downstream nodes.
27+
4. **Downstream Networking**: `modules/downstream` establishes a private subnet and a NAT gateway for isolated node provisioning.
28+
5. **Downstream Provisioning**: `modules/downstream` talks to the Rancher API to create Machine Configs (EC2 templates) and a new RKE2 Cluster definition.
29+
6. **State Syncing**: `rancher2_cluster_sync` blocks Terraform execution until the newly provisioned downstream cluster achieves an active state.
30+
31+
## Directory Structure Responsibilities
32+
33+
### `examples/downstream/` (Root Implementation Module)
34+
- Keep logic focused on setting up the upstream cluster, provider authentication, and delegating to local modules.
35+
- Outputs should output sensitive connection and state data generated from the upstream cluster (kubeconfig, tokens, etc).
36+
37+
### `examples/downstream/modules/downstream_securitygroups/`
38+
- Exclusively manage network boundaries and access rules (ingress/egress) for the downstream cluster.
39+
- Ensure traffic is allowed between the downstream cluster, the load balancer, and the upstream Rancher cluster's security group.
40+
41+
### `examples/downstream/modules/downstream/`
42+
- Manage downstream networking (subnets/Route Tables/NAT) to ensure downstream nodes are isolated from the public internet.
43+
- Dynamically provision Machine Configs and map node roles (control plane, etcd, worker).
44+
- Use `terraform_data` provisioners to execute credential patching via `addKeyToAmazonConfig.sh`.
45+
- **Do not expose direct SSH outputs** since nodes reside in a private subnet.

.claude/rules/terraform.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
paths:
3+
- "**/*.tf"
4+
---
5+
# Terraform Rules
6+
7+
As an AI Agent operating in this repository, you MUST strictly adhere to the following Terraform coding standards. Do not deviate from these rules under any circumstances.
8+
9+
## 1. Syntax & Formatting Constraints
10+
11+
* **Attribute Order**: You MUST declare resource attributes in this exact top-down order to ensure consistency:
12+
1. `count`
13+
2. `depends_on`
14+
3. `for_each`
15+
4. `source`
16+
5. `version`
17+
6. `triggers`
18+
7. *All other attributes*
19+
* **Explicit Dependencies**: You MUST always explicitly state `depends_on` blocks for resources and modules, even if Terraform can infer the dependency graph natively.
20+
* **Ternary Operations**: You MUST wrap all ternary operations in parentheses.
21+
* *Correct*: `attribute = (var.is_enabled ? true : false)`
22+
* *Incorrect*: `attribute = var.is_enabled ? true : false`
23+
* **Embedded Scripts**: Avoid embedded scripts if possible (use `file()` or `templatefile()`). If embedding is required, you MUST use heredoc syntax (`<<-EOT`).
24+
25+
## 2. Variables & Locals (Strict Mapping)
26+
27+
* **Locals Mapping**: ALL variables (`var.*`) MUST be immediately mapped to a `locals {}` block in the root of the module (usually `main.tf`).
28+
* **Resource Referencing**: Resources MUST ONLY reference `local.*`. You MUST NEVER reference `var.*` directly inside a `resource` or `module` block.
29+
30+
## 3. Count vs. Iteration
31+
32+
* **Count as a Feature Flag**: You MUST ONLY use `count` as a boolean feature flag to turn a resource on or off (`0` or `1`).
33+
* *Correct*: `count = (local.create_resource ? 1 : 0)`
34+
* **Never Iterate with Count**: You MUST NEVER use `count` to iterate over lists and create multiple instances of a resource. This causes cascading dependency destructions when list orders change. Use `for_each` instead.
35+
36+
## 4. Module Paradigms & Hierarchies
37+
38+
Understand the distinction between XMod (External), LMod (Local), and IMod (Implementation) modules.
39+
40+
* **No Nesting Local Modules**: You MUST NEVER nest an LMod (Local Module) inside another LMod. Treat LMods like function calls orchestrated by the Implementation Module (IMod).
41+
* **Module Tiers (Max 3 Levels)**:
42+
* **Core Modules**: Call only resources. NEVER call other modules.
43+
* **Primary Modules**: Call only Core Modules (exceptions allowed for `local_file`, `random`, or `terraform_data`). NEVER call raw API resources.
44+
* **Secondary Modules**: Call only Primary Modules. Represents large systems.
45+
* **Highly Opinionated Selectors**: Favor providing pre-defined configurations in `locals` (e.g., `prod-node-config`) rather than exposing raw, granular resource parameters via variables.
46+
47+
## 5. Provisioners & SSH Access
48+
49+
* **Script Paths**: When using `remote-exec` or connection strings, you MUST ALWAYS explicitly set the `script_path` attribute to avoid SELinux execution blocks in `/tmp`.
50+
* **SSH Agent Only**: Modules MUST NOT generate or accept private SSH keys or passwords as variables unless strictly necessary for a specific cloud-init sequence. Assume the user relies on a local SSH agent.
51+
52+
## 6. Testing Terminology
53+
54+
When writing tests, adhere to these conceptual boundaries:
55+
* **Unit Test**: Tests a single Local Module (LMod) in isolation.
56+
* **Integration Test**: Tests the interaction between two or more LMods.
57+
* **E2E Test**: Tests the entire Implementation Module (IMod) with real provider interactions.

.github/copilot-instructions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
You are GitHub Copilot, acting as the PR Code Reviewer for the terraform-rancher2-aws repository.
2+
Before reviewing any Pull Requests, generating code, or answering chat queries, you MUST read `AGENTS.md` located at the root of the workspace.
3+
AGENTS.md contains your specific persona instructions (to enforce rules without bikeshedding) and points to our strict Terraform paradigms.
4+
Do NOT proceed with your review until you have read and adopted the Copilot persona from `AGENTS.md`.

AGENTS.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# AI Agent Instructions for terraform-rancher2-aws
2+
3+
Hello! As an AI assistant working in this repository, please adhere to the following guidelines to ensure your code suggestions align with our project standards.
4+
5+
## 1. Agent Roles & Personas
6+
Depending on which AI tool is reading this, your expected behavior differs based on the developer's workflow:
7+
- **GitHub Copilot**: You act primarily as a **PR Code Reviewer**. Your job is to rigorously review code changes against `terraform.md` paradigms and catch structural/formatting issues. Do NOT suggest unnecessary changes or engage in pedantic "bikeshedding"; focus only on strictly enforced rules.
8+
- **Gemini Code Assist**: You act as a **Conversational Coding Partner**. Your job is to help the developer think through problems, explain complex Terraform architectures, and guide the implementation interactively.
9+
- **Claude**: You act as an **Autonomous Agent**. Your job is to quickly and efficiently execute tasks, fix PR review feedback generated by Copilot, and handle necessary coding chores with minimal conversational overhead.
10+
11+
## 2. Core Documentation
12+
Before making architectural or structural changes, you must review:
13+
- `.claude/rules/terraform.md` - This is our absolute source of truth for Terraform paradigms, attribute ordering, and module structuring.
14+
- `README.md` - For general deployment and testing requirements.
15+
16+
## 3. AI Workspace Structure (.claude)
17+
We have adopted the Claude CLI `.claude` directory structure as the universal standard for organizing AI context, regardless of which agent you are. Whenever you need to read or create AI-specific instructions, adhere to this layout:
18+
- **`CLAUDE.md` / `AGENTS.md`**: Project-level core instructions (this file).
19+
- **`.claude/rules/*.md`**: Topic-scoped instructions (e.g., Terraform guidelines, Go testing rules).
20+
- **`.claude/settings.json`**: Permissions, hooks, environment variables.
21+
- **`.claude/skills/<name>/SKILL.md`**: Reusable prompts and context loading skills.
22+
- **`.claude/commands/*.md`**: Single-file prompts.
23+
- **`.claude/agents/*.md`**: Subagent definitions.
24+
- **`.claude/output-styles/*.md`**: Custom response formatting.
25+
26+
## 4. Key Coding Paradigms (Strictly Enforced)
27+
- **Attribute Order:** Resources must follow this exact order: `count`, `depends_on`, `for_each`, `source`, `version`, `triggers`, then everything else.
28+
- **Variables in Locals:** All variables must be mapped to a `locals` block immediately. Resources must *only* reference `locals`, never `var.*` directly.
29+
- **Count as a Feature Flag:** Do not use `count` as an iterator to provision multiple resources. Use it strictly as a boolean feature flag (`0` or `1`).
30+
- **Module Tiers:** Understand the difference between Core, Primary, Secondary, and Implementation modules. **Never nest local modules!**
31+
- **Explicit Dependencies:** Always explicitly state `depends_on` blocks, even if Terraform can infer the dependency graph organically.
32+
33+
## 5. Sub-Project Contexts
34+
If you are asked to work in specific directories or examples, check the `.claude/skills/` directory for context loaders, or the local implementation documentation:
35+
- Downstream deployments: Read `.claude/skills/load-downstream-context/SKILL.md`
36+
- Production deployments: Read `examples/prod/README.md` (to be migrated to `.claude/skills/`)
37+
38+
## 6. Testing
39+
When writing tests or evaluating infrastructure, remember that state files are kept local for example implementations.
40+
Always advise developers to use the `cleanup.sh` and `run_tests.sh` scripts to handle leftover AWS resources and ensure an idempotent testing environment.

CLAUDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
You are an AI assistant working on the terraform-rancher2-aws project.
2+
Before making any code suggestions or analyzing the repo, you MUST read `AGENTS.md` in the root of this repository for your complete instructions.

GEMINI.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Gemini System Prompt
2+
3+
Before executing any commands, analyzing the repository, or generating code, you MUST read the `AGENTS.md` file located in the root of this repository for your complete instructions.

GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fmt:
55
cd test/tests; gofmt -s -w -e .; cd ../..
66

77
lint:
8-
tflint --recursive; \
8+
tflint --recursive --fix; \
99
cd test/tests; golangci-lint run; cd ../..; \
1010
actionlint
1111

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ If you are using remote state files and would like to be able to pass a backend
7171

7272
#### Paradigms and Expectations
7373

74-
Please make sure to read [terraform.md](./terraform.md) to understand the paradigms and expectations that this module has for development.
74+
Please make sure to read .claude/rules/terraform.md to understand the paradigms and expectations that this module has for development.
7575

7676
#### Environment
7777

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
provider "aws" {
2+
region = local.aws_region
3+
default_tags {
4+
tags = {
5+
Id = local.identifier
6+
Owner = local.owner
7+
}
8+
}
9+
}
10+
11+
locals {
12+
aws_region = base64decode(var.aws_region)
13+
identifier = base64decode(var.identifier)
14+
owner = base64decode(var.owner)
15+
rancher_address = base64decode(var.rancher_address)
16+
rancher_admin_password = base64decode(var.rancher_admin_password)
17+
rancher_admin_token = base64decode(var.rancher_admin_token)
18+
tls_certificate_chain = <<-EOT
19+
${base64decode(var.tls_certificate_chain)}
20+
EOT
21+
node_config_name = base64decode(var.node_config_name)
22+
aws_access_key_id = base64decode(var.aws_access_key_id)
23+
aws_secret_access_key = base64decode(var.aws_secret_access_key)
24+
aws_session_token = base64decode(var.aws_session_token)
25+
aws_region_letter = base64decode(var.aws_region_letter)
26+
downstream_security_group_name = base64decode(var.downstream_security_group_name)
27+
vpc_id = base64decode(var.vpc_id)
28+
load_balancer_security_group_id = base64decode(var.load_balancer_security_group_id)
29+
subnet_id = base64decode(var.subnet_id)
30+
node_info = jsondecode(base64decode(var.node_info))
31+
runner_ip = base64decode(var.runner_ip)
32+
ssh_access_key = base64decode(var.ssh_access_key)
33+
ssh_access_user = base64decode(var.ssh_access_user)
34+
rke2_version = base64decode(var.rke2_version)
35+
}
36+
37+
data "external" "login" {
38+
program = ["bash", "./modules/downstream/login.sh"]
39+
query = {
40+
api_url = local.rancher_address
41+
admin_password = local.rancher_admin_password
42+
admin_token = local.rancher_admin_token
43+
}
44+
}
45+
46+
provider "rancher2" {
47+
api_url = local.rancher_address
48+
token_key = data.external.login.result.admin_token
49+
ca_certs = local.tls_certificate_chain
50+
timeout = "300s"
51+
}
52+
53+
data "rancher2_cluster" "local" {
54+
depends_on = [
55+
data.external.login
56+
]
57+
name = "local"
58+
}
59+
60+
module "downstream" {
61+
depends_on = [
62+
data.rancher2_cluster.local
63+
]
64+
#
65+
source = "./modules/downstream"
66+
67+
name = local.node_config_name
68+
identifier = local.identifier
69+
owner = local.owner
70+
71+
aws_access_key_id = local.aws_access_key_id
72+
aws_secret_access_key = local.aws_secret_access_key
73+
aws_session_token = local.aws_session_token
74+
aws_region = local.aws_region
75+
aws_region_letter = local.aws_region_letter
76+
downstream_security_group_name = local.downstream_security_group_name
77+
78+
vpc_id = local.vpc_id
79+
load_balancer_security_group_id = local.load_balancer_security_group_id
80+
subnet_id = local.subnet_id
81+
82+
node_info = local.node_info
83+
direct_node_access = {
84+
runner_ip = local.runner_ip
85+
ssh_access_key = local.ssh_access_key
86+
ssh_access_user = local.ssh_access_user
87+
}
88+
rke2_version = local.rke2_version
89+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "cluster_data" {
2+
value = jsonencode(data.rancher2_cluster.local)
3+
sensitive = true
4+
}

0 commit comments

Comments
 (0)