@marcos_feitoza/devops-tf-circleci
v1.0.0
Published
Wrapper Terraform project to manage CircleCI using the local `terraform-circleci` module.
Readme
devops-tf-circleci
Wrapper Terraform project to manage CircleCI using the local terraform-circleci module.
Local run
- Export token:
export TF_VAR_circleci_api_token="<CIRCLECI_PERSONAL_TOKEN>"
- Plan:
terraform initterraform plan -var-file=../devops-tf-account-vars/global.tfvars -var-file=../devops-tf-account-vars/dev/ca-central-1/circleci.tfvars -out=tf_circleci.out
- Apply:
terraform apply --auto-approve \ -var-file=../devops-tf-account-vars/dev/ca-central-1/circleci.tfvars tf_circleci.out
Notes
organization_idis the CircleCI org UUID (not slug).- Keep
circleci_api_tokenonly in CircleCI Context/Env var, never intfvars.
circleci info org+--------------------------------------+--------------+
| ID | NAME |
+--------------------------------------+------------- |
| b0275876-d123-47cb-91e1-ec5e3ec3a3b1 | MarcosOps |
+--------------------------------------+--------------+#!/usr/bin/env bash
set -euo pipefail
set +x
ORG_ID="b0275876-d123-47cb-91e1-ec5e3ec3a3b1"
CTX="shared-ci-secrets"
# 1) cria o context se não existir
if ! circleci context list --org-id "$ORG_ID" --json | jq -e --arg c "$CTX" '.[] | select(.name==$c)' >/dev/null; then
circleci context create --org-id "$ORG_ID" "$CTX"
fi
# 2) grava/atualiza secrets (sobrescreve se já existir)
printf %s "$DOCKER_PASSWORD" | circleci context store-secret --org-id "$ORG_ID" "$CTX" DOCKER_PASSWORD
printf %s "$DOCKER_REPO" | circleci context store-secret --org-id "$ORG_ID" "$CTX" DOCKER_REPO
printf %s "$DOCKER_USERNAME" | circleci context store-secret --org-id "$ORG_ID" "$CTX" DOCKER_USERNAME
printf %s "$GH_TOKEN" | circleci context store-secret --org-id "$ORG_ID" "$CTX" GH_TOKEN
printf %s "$NPM_TOKEN" | circleci context store-secret --org-id "$ORG_ID" "$CTX" NPM_TOKEN
echo "OK: context e secrets aplicados."Elas aparecem em:
Organization Settings > Contexts > shared-ci-secretsElas não aparecem em Project Settings > Environment Variables quando vêm de context.
Elas aparecem em:
Organization Settings > Contexts > shared-ci-secrets