-
Notifications
You must be signed in to change notification settings - Fork 0
feat(03-backup): Scaleway backup S3 bucket foundation #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d8842cd
feat(03-backup): add Scaleway backup S3 bucket Terraform root
cfa6fc3
fix(03-backup): use OIDC auth for Infisical provider in CI
da13919
fix(03-backup): address PR #41 review comments
339acdb
fix(03-backup): read bucket name/region from terraform outputs
0b5c432
fix(03-backup): pass terraform outputs via env to avoid template inje…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| name: Terraform — Scaleway backup bucket | ||
|
|
||
| # Drives 03-backup/scaleway through the .github/actions/terraform composite action. | ||
| # | ||
| # Domain restriction — NO DESTROY in CI (FR-013): | ||
| # The backup domain is intentionally permanent infrastructure. Destroying the | ||
| # bucket from CI would silently erase production backups. Destruction must be | ||
| # a deliberate admin action with elevated credentials outside of this pipeline. | ||
| # Enforcement is layered: | ||
| # 1. No `destroy` option in workflow_dispatch (this file). | ||
| # 2. No `schedule → destroy` mapping in the command-resolution step. | ||
| # 3. `prevent_destroy = true` in 03-backup/scaleway/main.tf blocks | ||
| # `terraform destroy` even if someone runs it manually against this root. | ||
| # | ||
| # Trigger → command mapping: | ||
| # pull_request → plan (safety check, never mutates state) | ||
| # push to main → apply (the only automated mutation path) | ||
| # workflow_dispatch → plan | apply (operator override, explicit choice) | ||
| # | ||
| # State R/W uses the org state role (vars.AWS_TF_STATE_ROLE_ARN). | ||
| # Scaleway creds come from the `scaleway` environment. | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - '03-backup/scaleway/**' | ||
| - '.github/actions/terraform/**' | ||
| - '.github/workflows/backup_scaleway.yml' | ||
| push: | ||
| branches: [main] | ||
| paths: | ||
| - '03-backup/scaleway/**' | ||
| - '.github/actions/terraform/**' | ||
| - '.github/workflows/backup_scaleway.yml' | ||
| workflow_dispatch: | ||
| inputs: | ||
| command: | ||
| description: 'Terraform command. destroy is not available — see domain restriction above.' | ||
| type: choice | ||
| options: [plan, apply] | ||
| default: plan | ||
|
|
||
| # Concurrency is keyed on the Terraform workspace, not the branch. | ||
| # cancel-in-progress is false: Terraform state corruption from mid-run | ||
| # interrupts is far worse than waiting in queue. | ||
| concurrency: | ||
| group: backup-scaleway-03-backup-dev-bucket | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| terraform: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 20 | ||
| environment: scaleway | ||
| permissions: | ||
| id-token: write # mint OIDC tokens for AWS + Infisical | ||
| contents: read | ||
| env: | ||
| SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }} | ||
| SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }} | ||
| SCW_DEFAULT_ORGANIZATION_ID: ${{ vars.SCW_DEFAULT_ORGANIZATION_ID }} | ||
| SCW_DEFAULT_PROJECT_ID: ${{ vars.SCW_DEFAULT_PROJECT_ID }} | ||
| INFISICAL_MACHINE_IDENTITY_ID: ${{ vars.INFISICAL_MACHINE_IDENTITY_ID }} | ||
| steps: | ||
| - name: Assert state role ARN is present | ||
| env: | ||
| ROLE_ARN: ${{ vars.AWS_TF_STATE_ROLE_ARN }} | ||
| run: | | ||
| if [ -z "$ROLE_ARN" ]; then | ||
| echo "::error::vars.AWS_TF_STATE_ROLE_ARN is not set (provisioned by 01-iam/ci-managed/aws-state-access)." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Maps the GitHub event to a Terraform command. | ||
| # push → apply is the only automated mutation path (main branch only, per `on.push.branches`). | ||
| # workflow_dispatch lets an operator force plan or apply without a code change. | ||
| # Everything else (pull_request, etc.) stays read-only with plan. | ||
| - name: Resolve terraform command | ||
| id: cmd | ||
| env: | ||
| EVENT: ${{ github.event_name }} | ||
| DISPATCH_CMD: ${{ github.event.inputs.command }} | ||
| run: | | ||
| case "$EVENT" in | ||
| push) cmd=apply ;; | ||
| workflow_dispatch) cmd="${DISPATCH_CMD:-plan}" ;; | ||
| *) cmd=plan ;; | ||
| esac | ||
| echo "command=$cmd" >> "$GITHUB_OUTPUT" | ||
| echo "Resolved terraform command: $cmd (event: $EVENT)" | ||
|
|
||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| persist-credentials: false | ||
| fetch-depth: 1 | ||
|
|
||
| - uses: ./.github/actions/terraform | ||
| with: | ||
| root: 03-backup/scaleway | ||
| tfvars-file: 03-backup-dev-bucket.tfvars | ||
| command: ${{ steps.cmd.outputs.command }} | ||
| aws-role-arn: ${{ vars.AWS_TF_STATE_ROLE_ARN }} | ||
|
|
||
| # The backup bucket is permanent infrastructure — state always exists regardless | ||
| # of the terraform command. Read outputs unconditionally so downstream steps | ||
| # always have the live values from state rather than hardcoded strings. | ||
| - name: Read Terraform outputs | ||
| id: tf-outputs | ||
| run: | | ||
| outputs=$(terraform -chdir=03-backup/scaleway output -json) | ||
| echo "bucket_name=$(echo "$outputs" | jq -r '.bucket_name.value')" >> "$GITHUB_OUTPUT" | ||
| echo "bucket_region=$(echo "$outputs" | jq -r '.bucket_region.value')" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Verify backup bucket exists | ||
| if: steps.cmd.outputs.command == 'apply' | ||
| env: | ||
| BUCKET_NAME: ${{ steps.tf-outputs.outputs.bucket_name }} | ||
| BUCKET_REGION: ${{ steps.tf-outputs.outputs.bucket_region }} | ||
| run: | | ||
| curl -fsSL https://raw.githubusercontent.com/scaleway/scaleway-cli/master/scripts/get.sh | sh | ||
| export PATH="$HOME/.local/bin:$PATH" | ||
| scw object bucket get "$BUCKET_NAME" --region "$BUCKET_REGION" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "feature_directory": "specs/001-backup-s3-foundation" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| bucket_name = "backup-dev-id" | ||
| region = "fr-par" | ||
| project_id = "6283c05b-a4c7-4f83-a75f-83adad236d54" | ||
|
|
||
| ci_application_id = "4d50bbbd-e8a2-4b51-80c5-6aa47de669f7" | ||
|
|
||
| # Lifecycle defaults are accepted for dev: | ||
| # retention_days = 365 | ||
| # noncurrent_version_expiry_days = 30 | ||
| # cold_storage_enabled = true | ||
| # cold_storage_transition_days = 90 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| resource "scaleway_iam_application" "kubernetes" { | ||
| name = "backup-k8s-${terraform.workspace}" | ||
| description = "Kubernetes workload identity for ${terraform.workspace} — grants pods object read/write on the backup bucket via Infisical → ESO → Secret (no administrative rights, managed by terraform: 03-backup/scaleway/)." | ||
| } | ||
|
|
||
| resource "scaleway_iam_policy" "kubernetes" { | ||
| name = "backup-k8s-objects-${terraform.workspace}" | ||
| description = "Object-level read/write on the backup project. No bucket-level permissions — cannot delete or reconfigure the bucket." | ||
| application_id = scaleway_iam_application.kubernetes.id | ||
|
|
||
| rule { | ||
| project_ids = [var.project_id] | ||
| permission_set_names = ["ObjectStorageObjectsRead", "ObjectStorageObjectsWrite"] | ||
| } | ||
| } | ||
|
|
||
| # Scaleway requires every API key to carry an expiry. time_rotating keeps | ||
| # the expiry self-renewing: once the window elapses, the next apply rotates | ||
| # the key. Update the Kubernetes Secret (via ESO re-sync) after each rotation. | ||
| resource "time_rotating" "kubernetes_key" { | ||
| rotation_days = 365 | ||
| } | ||
|
|
||
| resource "scaleway_iam_api_key" "kubernetes" { | ||
| application_id = scaleway_iam_application.kubernetes.id | ||
| description = "Backup workload credentials for ${terraform.workspace}. Consumed via Infisical → ESO → Kubernetes Secret." | ||
| default_project_id = var.project_id | ||
| expires_at = time_rotating.kubernetes_key.rotation_rfc3339 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| resource "infisical_secret_folder" "backup" { | ||
| project_id = var.infisical_workspace_id | ||
| environment_slug = var.infisical_env_slug | ||
| folder_path = "/" | ||
| name = trimprefix(var.infisical_folder_path, "/") | ||
| description = "Backup workload credentials (managed by terraform: 03-backup/scaleway/)." | ||
| } | ||
|
|
||
| resource "infisical_secret" "access_key" { | ||
| name = "BACKUP_ACCESS_KEY" | ||
| value = scaleway_iam_api_key.kubernetes.access_key | ||
| env_slug = var.infisical_env_slug | ||
| workspace_id = var.infisical_workspace_id | ||
| folder_path = infisical_secret_folder.backup.path | ||
| } | ||
|
|
||
| resource "infisical_secret" "secret_key" { | ||
| name = "BACKUP_SECRET_KEY" | ||
| value = scaleway_iam_api_key.kubernetes.secret_key | ||
| env_slug = var.infisical_env_slug | ||
| workspace_id = var.infisical_workspace_id | ||
| folder_path = infisical_secret_folder.backup.path | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.