Skip to content

Commit

Permalink
fix: update Juju environment variable assignments
Browse files Browse the repository at this point in the history
Updated Juju environment variable assignments for consistency and correctness in various workflow
files and documentation.

- Before this commit, the environment variable assignments were inconsistent and used mixed
  formatting, including usage of `tr` command instead of relying on `raw` option for `yq` output
- After this commit, the assignments are consistent across all files, and we rely more on `yq`
  option to get the expected result, improving the readability and reducing the likelihood of
  errors.
  • Loading branch information
gfouillet committed Oct 21, 2024
1 parent 6e93012 commit 298b71b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 43 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ jobs:
# language=bash
run: |
CONTROLLER=$(juju whoami --format yaml | yq .controller)
echo "JUJU_AGENT_VERSION=$(juju show-controller | yq .$CONTROLLER.details.agent-version |tr -d '"')" >> $GITHUB_ENV
echo "JUJU_CONTROLLER_ADDRESSES=$(juju show-controller | yq .$CONTROLLER.details.api-endpoints | yq -r '. | join(",")')" >> $GITHUB_ENV
echo "JUJU_USERNAME=$(juju show-controller | yq .$CONTROLLER.account.user)" >> $GITHUB_ENV
echo "JUJU_PASSWORD=$(cat ~/.local/share/juju/accounts.yaml | yq .controllers.$CONTROLLER.password)" >> $GITHUB_ENV
echo "JUJU_CA_CERT<<EOF" >> $GITHUB_ENV
juju show-controller | yq .$CONTROLLER.details.ca-cert >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
cat << EOF >> $GITHUB_ENV
JUJU_AGENT_VERSION=$(juju show-controller | yq -r .$CONTROLLER.details.\"agent-version\")
JUJU_CONTROLLER_ADDRESSES=$(juju show-controller | yq .$CONTROLLER.details.\"api-endpoints\" | yq -r '. | join(",")')
JUJU_USERNAME=$(juju show-controller | yq -r .$CONTROLLER.account.user)
JUJU_PASSWORD=$(cat ~/.local/share/juju/accounts.yaml | yq -r .controllers.$CONTROLLER.password)
JUJU_CA_CERT=$(juju show-controller | yq -r .$CONTROLLER.details.\"ca-cert\")
EOF
- env:
TF_ACC: "1"
TEST_CLOUD: ${{ matrix.cloud }}
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/test_add_machine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ jobs:
# language=bash
run: |
CONTROLLER=$(juju whoami --format yaml | yq .controller)
echo "JUJU_AGENT_VERSION=$(juju show-controller | yq .$CONTROLLER.details.agent-version |tr -d '"')" >> $GITHUB_ENV
echo "JUJU_CONTROLLER_ADDRESSES=$(juju show-controller | yq .$CONTROLLER.details.api-endpoints | yq -r '. | join(",")')" >> $GITHUB_ENV
echo "JUJU_USERNAME=$(juju show-controller | yq .$CONTROLLER.account.user)" >> $GITHUB_ENV
echo "JUJU_PASSWORD=$(cat ~/.local/share/juju/accounts.yaml | yq .controllers.$CONTROLLER.password)" >> $GITHUB_ENV
echo "JUJU_CA_CERT<<EOF" >> $GITHUB_ENV
juju show-controller | yq .$CONTROLLER.details.ca-cert >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
cat << EOF >> $GITHUB_ENV
JUJU_AGENT_VERSION=$(juju show-controller | yq -r .$CONTROLLER.details.\"agent-version\")
JUJU_CONTROLLER_ADDRESSES=$(juju show-controller | yq .$CONTROLLER.details.\"api-endpoints\" | yq -r '. | join(",")')
JUJU_USERNAME=$(juju show-controller | yq -r .$CONTROLLER.account.user)
JUJU_PASSWORD=$(cat ~/.local/share/juju/accounts.yaml | yq -r .controllers.$CONTROLLER.password)
JUJU_CA_CERT=$(juju show-controller | yq -r .$CONTROLLER.details.\"ca-cert\")
EOF
- run: go mod download
- name: Create a new machine on lxd
run: |
Expand Down
23 changes: 13 additions & 10 deletions .github/workflows/test_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,21 @@ jobs:
sudo lxc network create public-br ipv4.address=10.170.80.1/24 ipv4.nat=true ipv6.address=none ipv6.nat=false
- name: "Set environment to configure provider"
# language=bash
run: |
run: |
CONTROLLER=$(juju whoami --format yaml | yq .controller)
cat << EOF >> $GITHUB_ENV
JUJU_AGENT_VERSION=$(juju show-controller | yq -r .$CONTROLLER.details.\"agent-version\")
JUJU_CONTROLLER_ADDRESSES=$(juju show-controller | yq .$CONTROLLER.details.\"api-endpoints\" | yq -r '. | join(",")')
JUJU_USERNAME=$(juju show-controller | yq -r .$CONTROLLER.account.user)
JUJU_PASSWORD=$(cat ~/.local/share/juju/accounts.yaml | yq -r .controllers.$CONTROLLER.password)
JUJU_CA_CERT=$(juju show-controller | yq -r .$CONTROLLER.details.\"ca-cert\")
TEST_MANAGEMENT_BR=10.150.40.0/24
TEST_PUBLIC_BR=10.170.80.0/24
EOF
echo "JUJU_AGENT_VERSION=$(juju show-controller | yq .$CONTROLLER.details.agent-version |tr -d '"')" >> $GITHUB_ENV
echo "JUJU_CONTROLLER_ADDRESSES=$(juju show-controller | yq .$CONTROLLER.details.api-endpoints | yq -r '. | join(",")')" >> $GITHUB_ENV
echo "JUJU_USERNAME=$(juju show-controller | yq .$CONTROLLER.account.user)" >> $GITHUB_ENV
echo "JUJU_PASSWORD=$(cat ~/.local/share/juju/accounts.yaml | yq .controllers.$CONTROLLER.password)" >> $GITHUB_ENV
echo "JUJU_CA_CERT<<EOF" >> $GITHUB_ENV
juju show-controller | yq .$CONTROLLER.details.ca-cert >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "TEST_MANAGEMENT_BR=10.150.40.0/24" >> $GITHUB_ENV
echo "TEST_PUBLIC_BR=10.170.80.0/24" >> $GITHUB_ENV
- name: "Set additional environment for LXD"
if: ${{ matrix.action-operator.cloud == 'lxd' }}
# language=bash
Expand Down
21 changes: 14 additions & 7 deletions .github/workflows/test_integration_jaas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,23 @@ jobs:
run: |
CONTROLLER=$(juju whoami --format yaml | yq .controller)
echo "IS_JAAS=true" >> $GITHUB_ENV
echo "JUJU_AGENT_VERSION=$(juju show-controller | yq .$CONTROLLER.details.agent-version |tr -d '"')" >> $GITHUB_ENV
echo "JUJU_CONTROLLER_ADDRESSES=$(juju show-controller | yq .$CONTROLLER.details.api-endpoints | yq -r '. | join(",")')" >> $GITHUB_ENV
echo "JUJU_CLIENT_ID=${{ steps.jaas.outputs.client-id }}" >> $GITHUB_ENV
echo "JUJU_CLIENT_SECRET=${{ steps.jaas.outputs.client-secret }}" >> $GITHUB_ENV
cat << EOF >> $GITHUB_ENV
IS_JAAS=true
JUJU_AGENT_VERSION=$(juju show-controller | yq -r .$CONTROLLER.details.\"agent-version\")
JUJU_CONTROLLER_ADDRESSES=$(juju show-controller | yq .$CONTROLLER.details.\"api-endpoints\" | yq -r '. | join(",")')
JUJU_USERNAME=$(juju show-controller | yq -r .$CONTROLLER.account.user)
JUJU_PASSWORD=$(cat ~/.local/share/juju/accounts.yaml | yq -r .controllers.$CONTROLLER.password)
JUJU_CLIENT_ID=${{ steps.jaas.outputs.client-id }}
JUJU_CLIENT_SECRET=${{ steps.jaas.outputs.client-secret }}
TEST_MANAGEMENT_BR=10.150.40.0/24
TEST_PUBLIC_BR=10.170.80.0/24
EOF
echo "JUJU_CA_CERT<<EOF" >> $GITHUB_ENV
echo "${{ steps.jaas.outputs.ca-cert }}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "TEST_MANAGEMENT_BR=10.150.40.0/24" >> $GITHUB_ENV
echo "TEST_PUBLIC_BR=10.170.80.0/24" >> $GITHUB_ENV
- run: go mod download
- env:
TF_ACC: "1"
Expand Down
10 changes: 5 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ provider "juju" {
Define the Juju controller credentials in the provider definition via environment variables. These can be set up as follows:

```shell
export CONTROLLER=$(juju whoami | yq .Controller)
export JUJU_CONTROLLER_ADDRESSES="$(juju show-controller | yq '.[$CONTROLLER]'.details.\"api-endpoints\" | tr -d "[]' "|tr -d '"'|tr -d '\n')"
export JUJU_USERNAME="$(cat ~/.local/share/juju/accounts.yaml | yq .controllers.$CONTROLLER.user|tr -d '"')"
export JUJU_PASSWORD="$(cat ~/.local/share/juju/accounts.yaml | yq .controllers.$CONTROLLER.password|tr -d '"')"
export JUJU_CA_CERT="$(juju show-controller $(echo $CONTROLLER|tr -d '"') | yq '.[$CONTROLLER]'.details.\"ca-cert\"|tr -d '"'|sed 's/\\n/\n/g')"
export CONTROLLER=$(juju whoami --format yaml | yq .controller)
export JUJU_CONTROLLER_ADDRESSES=$(juju show-controller | yq .$CONTROLLER.details.\"api-endpoints\" | yq -r '. | join(",")')
export JUJU_USERNAME=$(juju show-controller | yq -r .$CONTROLLER.account.user)
export JUJU_PASSWORD=$(cat ~/.local/share/juju/accounts.yaml | yq -r .controllers.$CONTROLLER.password)
export JUJU_CA_CERT=$(juju show-controller | yq -r .$CONTROLLER.details.\"ca-cert\")
```

### Populated by the provider via the juju CLI client.
Expand Down
10 changes: 5 additions & 5 deletions templates/index.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ provider "juju" {
Define the Juju controller credentials in the provider definition via environment variables. These can be set up as follows:

```shell
export CONTROLLER=$(juju whoami | yq .Controller)
export JUJU_CONTROLLER_ADDRESSES="$(juju show-controller | yq '.[$CONTROLLER]'.details.\"api-endpoints\" | tr -d "[]' "|tr -d '"'|tr -d '\n')"
export JUJU_USERNAME="$(cat ~/.local/share/juju/accounts.yaml | yq .controllers.$CONTROLLER.user|tr -d '"')"
export JUJU_PASSWORD="$(cat ~/.local/share/juju/accounts.yaml | yq .controllers.$CONTROLLER.password|tr -d '"')"
export JUJU_CA_CERT="$(juju show-controller $(echo $CONTROLLER|tr -d '"') | yq '.[$CONTROLLER]'.details.\"ca-cert\"|tr -d '"'|sed 's/\\n/\n/g')"
export CONTROLLER=$(juju whoami --format yaml | yq .controller)
export JUJU_CONTROLLER_ADDRESSES=$(juju show-controller | yq .$CONTROLLER.details.\"api-endpoints\" | yq -r '. | join(",")')
export JUJU_USERNAME=$(juju show-controller | yq -r .$CONTROLLER.account.user)
export JUJU_PASSWORD=$(cat ~/.local/share/juju/accounts.yaml | yq -r .controllers.$CONTROLLER.password)
export JUJU_CA_CERT=$(juju show-controller | yq -r .$CONTROLLER.details.\"ca-cert\")
```

### Populated by the provider via the juju CLI client.
Expand Down

0 comments on commit 298b71b

Please sign in to comment.