Skip to content

Commit

Permalink
Get ARGOCD_AUTH_TOKEN and KUBECONFIG from terraform outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanevet committed Nov 23, 2020
1 parent d728680 commit 75d5f8b
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 48 deletions.
19 changes: 3 additions & 16 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ jobs:
TF_VAR_repo_url=$GITHUB_SERVER_URL/${{ github.actor }}/camptocamp-devops-stack.git \
TF_VAR_target_revision=${{ github.head_ref }} \
../../scripts/provision.sh
. ../../scripts/get-argocd-auth-token.sh
while ! argocd app wait apps --health --timeout 30; do argocd app list -owide; done
../../scripts/wait-for-app-of-apps.sh
env:
CLUSTER_NAME: default
ARGOCD_OPTS: "--plaintext --port-forward --port-forward-namespace argocd"
KUBECONFIG: terraform/kubeconfig.yaml
- name: Destroy cluster
run: |
TF_VAR_repo_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git \
Expand Down Expand Up @@ -60,12 +57,9 @@ jobs:
TF_VAR_repo_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git \
TF_VAR_target_revision=${{ github.base_ref }} \
../../scripts/provision.sh
. ../../scripts/get-argocd-auth-token.sh
while ! argocd app wait apps --health --timeout 30; do argocd app list -owide; done
../../scripts/wait-for-app-of-apps.sh
env:
CLUSTER_NAME: default
ARGOCD_OPTS: "--plaintext --port-forward --port-forward-namespace argocd"
KUBECONFIG: terraform/kubeconfig.yaml
- uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
Expand All @@ -80,25 +74,18 @@ jobs:
- name: App-diff on ref
run: |
export PATH="$HOME/bin:$PATH"
. ../../scripts/get-argocd-auth-token.sh
chmod 0600 "$KUBECONFIG"
../../scripts/app-diff.sh
env:
CLUSTER_NAME: default
ARGOCD_OPTS: "--plaintext --port-forward --port-forward-namespace argocd"
KUBECONFIG: terraform/kubeconfig.yaml
- name: Update cluster
run: |
export PATH="$HOME/bin:$PATH"
TF_VAR_repo_url=$GITHUB_SERVER_URL/${{ github.actor }}/camptocamp-devops-stack.git \
TF_VAR_target_revision=${{ github.head_ref }} \
../../scripts/provision.sh
. ../../scripts/get-argocd-auth-token.sh
while ! argocd app wait apps --health --timeout 30; do argocd app list -owide; done
../../scripts/wait-for-app-of-apps.sh
env:
CLUSTER_NAME: default
ARGOCD_OPTS: "--plaintext --port-forward --port-forward-namespace argocd"
KUBECONFIG: terraform/kubeconfig.yaml
- name: Destroy cluster
run: |
TF_VAR_repo_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git \
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ jobs:
TF_VAR_repo_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git \
TF_VAR_target_revision=${GITHUB_REF##*/} \
../../scripts/provision.sh
. ../../scripts/get-argocd-auth-token.sh
while ! argocd app wait apps --health --timeout 30; do argocd app list -owide; done
../../scripts/wait-for-app-of-apps.sh
env:
CLUSTER_NAME: default
ARGOCD_OPTS: "--plaintext --port-forward --port-forward-namespace argocd"
KUBECONFIG: terraform/kubeconfig.yaml
- name: Destroy cluster
run: |
TF_VAR_repo_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git \
Expand Down
5 changes: 5 additions & 0 deletions modules/eks-aws/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
output "argocd_auth_token" {
description = "The token to set in ARGOCD_AUTH_TOKEN environment variable."
value = module.argocd.argocd_auth_token
}

output "cluster_id" {
description = "The name/id of the EKS cluster. Will block on cluster creation until the cluster is really ready"
value = module.cluster.cluster_id
Expand Down
5 changes: 5 additions & 0 deletions modules/k3os-libvirt/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
output "argocd_auth_token" {
description = "The token to set in ARGOCD_AUTH_TOKEN environment variable."
value = module.argocd.argocd_auth_token
}

output "base_domain" {
value = local.base_domain
}
Expand Down
5 changes: 5 additions & 0 deletions modules/k3s-docker/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
output "argocd_auth_token" {
description = "The token to set in ARGOCD_AUTH_TOKEN environment variable."
value = module.argocd.argocd_auth_token
}

output "base_domain" {
value = local.base_domain
}
Expand Down
13 changes: 11 additions & 2 deletions scripts/app-diff.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
#!/bin/sh -e
#!/bin/bash -e

ARGOCD_AUTH_TOKEN=$(jq -r '.ARGOCD_AUTH_TOKEN.value' terraform/outputs.json)
export ARGOCD_AUTH_TOKEN

ARGOCD_OPTS="--plaintext --port-forward --port-forward-namespace argocd"
export ARGOCD_OPTS

KUBECONFIG_CONTENT=$(jq -r '.KUBECONFIG_CONTENT.value' terraform/outputs.json)
export KUBECONFIG_CONTENT

export KUBECTL_EXTERNAL_DIFF="diff -u"

for app_dir in ../../argocd/*;
do
app=${app_dir#../../argocd/}
test -f "$app_dir/Chart.yaml" && helm dependency update "$app_dir"
argocd app diff "$app" --local "$app_dir" || true
KUBECONFIG=<(echo "$KUBECONFIG_CONTENT") argocd app diff "$app" --local "$app_dir" || true
done
26 changes: 0 additions & 26 deletions scripts/get-argocd-auth-token.sh

This file was deleted.

1 change: 1 addition & 0 deletions scripts/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export TF_WORKSPACE="$CLUSTER_NAME"
cd terraform || exit
terraform init -upgrade
terraform plan
terraform output -json > outputs.json
cd - || exit
1 change: 1 addition & 0 deletions scripts/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ helm dependency update "$(jq -r '.Modules[]|select(.Key == "cluster").Dir + "/..

terraform apply --auto-approve
terraform plan --detailed-exitcode
terraform output -json > outputs.json
cd - || exit
15 changes: 15 additions & 0 deletions scripts/wait-for-app-of-apps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash -e

ARGOCD_AUTH_TOKEN=$(jq -r '.ARGOCD_AUTH_TOKEN.value' terraform/outputs.json)
export ARGOCD_AUTH_TOKEN

ARGOCD_OPTS="--plaintext --port-forward --port-forward-namespace argocd"
export ARGOCD_OPTS

KUBECONFIG_CONTENT=$(jq -r '.KUBECONFIG_CONTENT.value' terraform/outputs.json)
export KUBECONFIG_CONTENT

while ! KUBECONFIG=<(echo "$KUBECONFIG_CONTENT") argocd app wait apps --health --timeout 30
do
KUBECONFIG=<(echo "$KUBECONFIG_CONTENT") argocd app list -owide
done
10 changes: 10 additions & 0 deletions tests/k3os-libvirt/terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ output "base_domain" {
value = module.cluster.base_domain
}

output "ARGOCD_AUTH_TOKEN" {
sensitive = true
value = module.cluster.argocd_auth_token
}

output "KUBECONFIG_CONTENT" {
sensitive = true
value = module.cluster.kubeconfig
}

output "argocd_url" {
value = format("https://argocd.apps.%s", module.cluster.base_domain)
}
Expand Down
10 changes: 10 additions & 0 deletions tests/k3s-docker/terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ output "base_domain" {
value = module.cluster.base_domain
}

output "ARGOCD_AUTH_TOKEN" {
sensitive = true
value = module.cluster.argocd_auth_token
}

output "KUBECONFIG_CONTENT" {
sensitive = true
value = module.cluster.kubeconfig
}

output "argocd_url" {
value = format("https://argocd.apps.%s", module.cluster.base_domain)
}
Expand Down

0 comments on commit 75d5f8b

Please sign in to comment.