Skip to content
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

Generate & Publish based on tf provider fork #204

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ env:
# Common users. We can't run a step 'if secrets.XXX != ""' but we can run a
# step 'if env.XXX != ""', so we copy these to succinctly test whether
# credentials have been provided before trying to run steps that need them.
UPBOUND_MARKETPLACE_PUSH_ROBOT_USR: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR }}
UPBOUND_MARKETPLACE_PUSH_ROBOT_USR: ${{ vars.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR }}
TERRAFORM_PROVIDER_REPO: ${{ vars.TERRAFORM_PROVIDER_REPO }}
TERRAFORM_PROVIDER_VERSION: ${{ vars.TERRAFORM_PROVIDER_VERSION }}
XPKG_REG_ORGS: ${{ vars.XPKG_REG_ORGS }}
XPKG_REG_ORGS_NO_PROMOTE: ${{ vars.XPKG_REG_ORGS_NO_PROMOTE }}

jobs:
detect-noop:
Expand Down Expand Up @@ -235,9 +239,18 @@ jobs:
if: env.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR != ''
with:
registry: xpkg.upbound.io
username: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR }}
username: ${{ env.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR }}
password: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_PSW }}

- name: Install up
if: env.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR != ''
run: curl -sL "https://cli.upbound.io" | VERSION=v0.31.0 sh && sudo mv up /usr/local/bin/

- name: Login to Upbound
if: env.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR != ''
run: |
echo "${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_PSW }}" | up login -t -

- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
Expand Down
28 changes: 23 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ export TERRAFORM_VERSION ?= 1.5.7
TERRAFORM_VERSION_VALID := $(shell [ "$(TERRAFORM_VERSION)" = "`printf "$(TERRAFORM_VERSION)\n1.6" | sort -V | head -n1`" ] && echo 1 || echo 0)

export TERRAFORM_PROVIDER_SOURCE ?= keycloak/keycloak
export TERRAFORM_PROVIDER_REPO ?= https://github.com/keycloak/terraform-provider-keycloak
export TERRAFORM_PROVIDER_VERSION ?= 4.5.0
export TERRAFORM_PROVIDER_REPO := $(if $(TERRAFORM_PROVIDER_REPO),$(TERRAFORM_PROVIDER_REPO),https://github.com/keycloak/terraform-provider-keycloak)
export TERRAFORM_PROVIDER_VERSION := $(if $(TERRAFORM_PROVIDER_VERSION),$(TERRAFORM_PROVIDER_VERSION),4.5.0)
export TERRAFORM_PROVIDER_DOWNLOAD_NAME ?= terraform-provider-keycloak
export TERRAFORM_PROVIDER_DOWNLOAD_URL_PREFIX ?= ${TERRAFORM_PROVIDER_REPO}/releases/download/v$(TERRAFORM_PROVIDER_VERSION)
export TERRAFORM_NATIVE_PROVIDER_BINARY ?= terraform-provider-keycloak_v4.5.0
export TERRAFORM_NATIVE_PROVIDER_BINARY ?= terraform-provider-keycloak_v$(TERRAFORM_PROVIDER_VERSION)
export TERRAFORM_DOCS_PATH ?= docs/resources
export TERRAFORM_FILE_MIRROR ?= .terraform.d/plugins
export TERRAFORM_FILE_MIRROR_REPO ?= ${TERRAFORM_FILE_MIRROR}/registry.terraform.io
export TF_CLI_CONFIG_FILE ?=

export GOLANGCILINT_VERSION ?= 1.57.2

Expand Down Expand Up @@ -123,11 +126,26 @@ $(TERRAFORM): check-terraform-version
$(TERRAFORM_PROVIDER_SCHEMA): $(TERRAFORM)
@$(INFO) generating provider schema for $(TERRAFORM_PROVIDER_SOURCE) $(TERRAFORM_PROVIDER_VERSION)
@mkdir -p $(TERRAFORM_WORKDIR)
@$(MAKE) download-tf-provider-platforms
@echo '{"terraform":[{"required_providers":[{"provider":{"source":"'"$(TERRAFORM_PROVIDER_SOURCE)"'","version":"'"$(TERRAFORM_PROVIDER_VERSION)"'"}}],"required_version":"'"$(TERRAFORM_VERSION)"'"}]}' > $(TERRAFORM_WORKDIR)/main.tf.json
@$(TERRAFORM) -chdir=$(TERRAFORM_WORKDIR) init > $(TERRAFORM_WORKDIR)/terraform-logs.txt 2>&1
@$(TERRAFORM) -chdir=$(TERRAFORM_WORKDIR) providers schema -json=true > $(TERRAFORM_PROVIDER_SCHEMA) 2>> $(TERRAFORM_WORKDIR)/terraform-logs.txt
@echo 'provider_installation { filesystem_mirror { path = "$(TERRAFORM_WORKDIR)/$(TERRAFORM_FILE_MIRROR)" include = ["*/*/*"] } }' > $(TERRAFORM_WORKDIR)/config.tfrc
@TF_CLI_CONFIG_FILE=$(TERRAFORM_WORKDIR)/config.tfrc $(TERRAFORM) -chdir=$(TERRAFORM_WORKDIR) init -no-color > $(TERRAFORM_WORKDIR)/terraform-logs.txt 2>&1
@TF_CLI_CONFIG_FILE=$(TERRAFORM_WORKDIR)/config.tfrc $(TERRAFORM) -chdir=$(TERRAFORM_WORKDIR) providers schema -json=true > $(TERRAFORM_PROVIDER_SCHEMA) 2>> $(TERRAFORM_WORKDIR)/terraform-logs.txt
@$(OK) generating provider schema for $(TERRAFORM_PROVIDER_SOURCE) $(TERRAFORM_PROVIDER_VERSION)

download-tf-provider-platforms: $(foreach p,$(PLATFORMS), download-tf-provider-platform.$(p))

download-tf-provider-platform.%:
@$(MAKE) download-tf-provider-platform PLATFORM=$*

download-tf-provider-platform:
@PLATFORM=$*
@$(INFO) downloading provider for platform $(PLATFORM)
@mkdir -p $(TERRAFORM_WORKDIR)/$(TERRAFORM_FILE_MIRROR_REPO)/$(TERRAFORM_PROVIDER_SOURCE)/$(TERRAFORM_PROVIDER_VERSION)/${PLATFORM}
@curl -fsSL ${TERRAFORM_PROVIDER_DOWNLOAD_URL_PREFIX}/${TERRAFORM_PROVIDER_DOWNLOAD_NAME}_${TERRAFORM_PROVIDER_VERSION}_${PLATFORM}.zip -o $(TERRAFORM_WORKDIR)/$(TERRAFORM_FILE_MIRROR_REPO)/$(TERRAFORM_PROVIDER_SOURCE)/$(TERRAFORM_PROVIDER_VERSION)/${PLATFORM}/terraform.zip
@unzip -o -qq $(TERRAFORM_WORKDIR)/$(TERRAFORM_FILE_MIRROR_REPO)/$(TERRAFORM_PROVIDER_SOURCE)/$(TERRAFORM_PROVIDER_VERSION)/${PLATFORM}/terraform.zip -d $(TERRAFORM_WORKDIR)/$(TERRAFORM_FILE_MIRROR_REPO)/$(TERRAFORM_PROVIDER_SOURCE)/$(TERRAFORM_PROVIDER_VERSION)/${PLATFORM}/
@rm $(TERRAFORM_WORKDIR)/$(TERRAFORM_FILE_MIRROR_REPO)/$(TERRAFORM_PROVIDER_SOURCE)/$(TERRAFORM_PROVIDER_VERSION)/${PLATFORM}/terraform.zip

pull-docs:
@if [ ! -d "$(WORK_DIR)/$(TERRAFORM_PROVIDER_SOURCE)" ]; then \
mkdir -p "$(WORK_DIR)/$(TERRAFORM_PROVIDER_SOURCE)" && \
Expand Down
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ You can explore the available custom resources:

Run code-generation pipeline:
```console
go run cmd/generator/main.go "$PWD"
go install golang.org/x/tools/cmd/goimports@latest
go run cmd/generator/main.go "$(pwd)"
```

Checkout sub-repositories:
Expand Down Expand Up @@ -184,7 +185,42 @@ Build binary:
make build
```

## Regression Tests
### Custom Terraform Provider

If you want to build this crossplane provider on top of a forked `terraform-provider-keycloak` follow these instructions:

1. Execute code generation:
```
TERRAFORM_PROVIDER_REPO=https://github.com/<owner>/terraform-provider-keycloak \
TERRAFORM_PROVIDER_VERSION=1.0.0 \
make generate
```
**Hint:** `TERRAFORM_PROVIDER_VERSION` must be a Release. Releases can be found here: `https://github.com/<owner>/terraform-provider-keycloak/releases`.
Every ReleaseName should have the prefix "v" (i.e 'v1.0.0'). But if you specify the `TERRAFORM_PROVIDER_VERSION` you need to
skip that prefix (i.e. '1.0.0')

2. Use forked repo as go dependency:
```
go mod edit -replace="github.com/keycloak/terraform-provider-keycloak@v0.0.0-20241206084240-f87470c95855=github.com/<owner>/terraform-provider-keycloak@v1.0.0"
go mod tidy
```
**Hint:** You can also specify the version as `github.com/<owner>/terraform-provider-keycloak@v0.0.0-<timestamp>-<commitHash>`

3. Build and publish to custom repo

If you want to build and publish with CI, then add following to [GithubRepo > Settings > Secrets and variables > Actions](https://github.com/keycloak/provider-keycloak/settings/secrets/actions)

Variables > Repository variables
* TERRAFORM_PROVIDER_REPO=`https://github.com/<owner>/terraform-provider-keycloak`
* TERRAFORM_PROVIDER_VERSION=`1.0.0`
* UPBOUND_MARKETPLACE_PUSH_ROBOT_USR=`<user>`
* XPKG_REG_ORGS=`xpkg.upbound.io/<repo>`
* XPKG_REG_ORGS_NO_PROMOTE=`xpkg.upbound.io/<repo>`

Secrets > Repository secrets
* UPBOUND_MARKETPLACE_PUSH_ROBOT_PSW=`<password>`

## Regression Tests
TODO: Add regression test docs

## Report a Bug
Expand Down
Loading