diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 8f01e71..11ec0f8 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -41,4 +41,4 @@ jobs: ./generate-provider-json.sh artifacts.json metadata.json env: TERRALIST_API: https://terralist.garm-provider-test.t09.de/v1/api - TERRALIST_API_KEY: ${{ secrets.TERRALIST_API_KEY }} \ No newline at end of file + TERRALIST_API_KEY: ${{ secrets.TERRALIST_API_KEY }} diff --git a/README.md b/README.md index d2f1b50..e94483b 100644 --- a/README.md +++ b/README.md @@ -50,17 +50,11 @@ mkdir -p ~/.terraform.d/plugins/registry.terraform.io/DevFW-CICD/edge-connect/1. cp terraform-provider-edge-connect ~/.terraform.d/plugins/registry.terraform.io/DevFW-CICD/edge-connect/1.0.0/darwin_arm64/ ``` -Note: Adjust the path based on your OS and architecture (e.g., `linux_amd64`, `darwin_amd64`, etc.) +> Note: Adjust the path based on your OS and architecture (e.g., `linux_amd64`, `darwin_amd64`, etc.) -## Usage +4. Generate the binary by running `go install .` from the repository root. This installs the provider binary to `$HOME/go/bin` and means that `terraform init` is not necessary. -### Provider Configuration - -As the provider is currently not officially registered for public download, terraform must be configured to use a locally built version. - -To generate the binary run `go install .` from the repository root. This installs the provider binary to `$HOME/go/bin` and means that `terraform init` is not necessary. - -You will also need a `~/.terraformrc` file with the following contents. `` should refer to your `$HOME` directory. +5. You will also need a `~/.terraformrc` file with the following contents. `` should refer to your `$HOME` directory. ```hcl provider_installation { @@ -76,7 +70,11 @@ provider_installation { } ``` -You can then reference the local provider in your `.tf` files as follows: +## Usage + +### Provider Configuration + +The provider must be configured with credentials and a URL. This can be done with a token in your code: ```hcl provider "edge-connect" { @@ -85,7 +83,7 @@ provider "edge-connect" { } ``` -Or using basic authentication: +Or with basic authentication: ```hcl provider "edge-connect" { @@ -95,7 +93,7 @@ provider "edge-connect" { } ``` -Configuration can also be provided via environment variables: +Or without code changes, via environment variables: - `EDGE_CONNECT_BASE_URL` - `EDGE_CONNECT_TOKEN` - `EDGE_CONNECT_USERNAME` diff --git a/generate-provider-json.sh b/generate-provider-json.sh index 20506aa..1cd1124 100755 --- a/generate-provider-json.sh +++ b/generate-provider-json.sh @@ -9,22 +9,24 @@ METADATA_FILE=$2 TERRALIST_API=${TERRALIST_API:-https://terralist.garm-provider-test.t09.de/v1/api} TERRALIST_API_KEY=${TERRALIST_API_KEY:-invalid-key} -echo -e "\n__ARTIFACTS_FILE__" -cat $ARTIFACTS_FILE | jq . -echo -e "\n__METADATA_FILE__" -cat $METADATA_FILE | jq . - VERSION=$(cat $METADATA_FILE | jq -r '.version') -jq --arg base "$FORGEJO_SERVER_URL/$FORGEJO_REPOSITORY/releases/download" --arg version "$VERSION" ' +BASE_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/download" + +if ! [[ "$BASE_URL" =~ "terraform" ]]; then + echo "Error: GITHUB_ environment variables not set correctly" >&2 + exit 1 +fi + +jq --arg base_url "$BASE_URL" --arg version "$VERSION" ' { protocols: ["6"], shasums: ( { - url: ($base + "/v" + $version + "/" + (.[] + url: ($base_url + "/v" + $version + "/" + (.[] | select(.type=="Checksum").name)), - signature_url: ($base + "/v" + $version + "/" + (.[] + signature_url: ($base_url + "/v" + $version + "/" + (.[] | select(.type=="Signature").name)) } ), @@ -35,7 +37,7 @@ jq --arg base "$FORGEJO_SERVER_URL/$FORGEJO_REPOSITORY/releases/download" --arg | { os: .goos, arch: .goarch, - download_url: ($base + "/v" + $version + "/" + .name), + download_url: ($base_url + "/v" + $version + "/" + .name), shasum: (.extra.Checksum | sub("^sha256:";"")) } ]