diff --git a/.github/workflows/community-moderation.yml b/.github/workflows/community-moderation.yml index 84077d80..edfe741d 100644 --- a/.github/workflows/community-moderation.yml +++ b/.github/workflows/community-moderation.yml @@ -1,5 +1,5 @@ # WARNING: This file was build based on https://github.com/pulumi/ci-mgmt -# but it is currently not in sync. Any updates may be done manually +# but it is currently not in sync. Any update must be done manually name: warn-codegen on: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 753c924e..f8fd6a78 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,5 +1,5 @@ # WARNING: This file was build based on https://github.com/pulumi/ci-mgmt -# but it is currently not in sync. Any updates may be done manually +# but it is currently not in sync. Any update must be done manually name: lint on: diff --git a/.github/workflows/run-acceptance-tests.yml b/.github/workflows/run-acceptance-tests.yml index 6333eac4..7722f928 100644 --- a/.github/workflows/run-acceptance-tests.yml +++ b/.github/workflows/run-acceptance-tests.yml @@ -1,5 +1,5 @@ # WARNING: This file was build based on https://github.com/pulumi/ci-mgmt -# but it is currently not in sync. Any updates may be done manually +# but it is currently not in sync. Any update must be done manually name: run-acceptance-tests on: diff --git a/.github/workflows/upgrade-bridge.yml b/.github/workflows/upgrade-bridge.yml new file mode 100644 index 00000000..0bf39d61 --- /dev/null +++ b/.github/workflows/upgrade-bridge.yml @@ -0,0 +1,85 @@ +# WARNING: This file was build based on https://github.com/pulumi/ci-mgmt +# but it is currently not in sync. Any update must be done manually + +name: Upgrade bridge +on: + repository_dispatch: + types: + - upgrade-bridge + workflow_dispatch: + inputs: + target-bridge-version: + description: pulumi-terraform-bridge version or hash reference + required: false + type: string + default: "latest" + pr-reviewers: + description: Reviewers to assign to the auto-opened pull request + required: false + type: string + default: "" + pr-description: + description: Extra description to add to the auto-opened pull request + required: false + type: string + default: "" + automerge: + description: Mark created PR for auto-merging? + required: false + type: boolean + default: false +env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +jobs: + upgrade_provider: + name: upgrade-provider + runs-on: ubuntu-latest + steps: + - name: Call upgrade provider action + if: github.event_name == 'workflow_dispatch' + uses: pulumi/pulumi-upgrade-provider-action@v0.0.9 + with: + kind: bridge + email: noreply@github.com + username: GitHub + automerge: ${{ inputs.automerge }} + target-bridge-version: ${{ inputs.target-bridge-version }} + pr-reviewers: ${{ inputs.pr-reviewers }} + pr-description: ${{ inputs.pr-description }} + - name: Call upgrade provider action + if: github.event_name == 'repository_dispatch' + uses: pulumi/pulumi-upgrade-provider-action@v0.0.9 + with: + kind: bridge + email: noreply@github.com + username: GitHub + automerge: ${{ github.event.client_payload.automerge }} + target-bridge-version: ${{ github.event.client_payload.target-bridge-version }} + pr-reviewers: ${{ github.event.client_payload.pr-reviewers }} + pr-description: ${{ github.event.client_payload.pr-description }} + ## TODO + # - env: + # SLACK_CHANNEL: provider-upgrade-publish-status + # SLACK_COLOR: "#7CFC00" + # SLACK_ICON_EMOJI: ":taco:" + # SLACK_MESSAGE: >- + # Upgrade succeeded :heart_decoration: + + # PR opened at github.com/pulumi/${{ github.event.repository.name }}/pulls + # SLACK_TITLE: ${{ github.event.repository.name }} upgrade result + # SLACK_USERNAME: provider-bot + # SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} + # name: Send Upgrade Success To Slack + # uses: rtCamp/action-slack-notify@v2 + # - env: + # SLACK_CHANNEL: provider-upgrade-publish-status + # SLACK_COLOR: "#FF0000" + # SLACK_ICON_EMOJI: ":taco:" + # SLACK_MESSAGE: " Upgrade failed :x:" + # SLACK_TITLE: ${{ github.event.repository.name }} upgrade result + # SLACK_USERNAME: provider-bot + # SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} + # if: failure() + # name: Send Upgrade Failure To Slack + # uses: rtCamp/action-slack-notify@v2 \ No newline at end of file diff --git a/.github/workflows/upgrade-provider.yml b/.github/workflows/upgrade-provider.yml new file mode 100644 index 00000000..5641b56d --- /dev/null +++ b/.github/workflows/upgrade-provider.yml @@ -0,0 +1,43 @@ +# WARNING: This file was build based on https://github.com/pulumi/ci-mgmt +# but it is currently not in sync. Any update must be done manually + +env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +jobs: + upgrade_provider: + if: ${{ contains(github.event.issue.title, 'Upgrade terraform-provider-') || github.event_name == 'workflow_dispatch' }} + name: upgrade-provider + runs-on: ubuntu-latest + steps: + - name: Call upgrade provider action + uses: pulumi/pulumi-upgrade-provider-action@v0.0.9 + with: + kind: all + email: noreply@github.com + username: GitHub + ## TODO + # - env: + # SLACK_CHANNEL: provider-upgrade-publish-status + # SLACK_COLOR: "#7CFC00" + # SLACK_ICON_EMOJI: ":taco:" + # SLACK_MESSAGE: >- + # Upgrade succeeded :heart_decoration: + + # PR opened at github.com/pulumi/${{ github.event.repository.name }}/pulls + # SLACK_TITLE: ${{ github.event.repository.name }} upgrade result + # SLACK_USERNAME: provider-bot + # SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} + # name: Send Upgrade Success To Slack + # uses: rtCamp/action-slack-notify@v2 + # - env: + # SLACK_CHANNEL: provider-upgrade-publish-status + # SLACK_COLOR: "#FF0000" + # SLACK_ICON_EMOJI: ":taco:" + # SLACK_MESSAGE: " Upgrade failed :x:" + # SLACK_TITLE: ${{ github.event.repository.name }} upgrade result + # SLACK_USERNAME: provider-bot + # SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} + # if: failure() + # name: Send Upgrade Failure To Slack + # uses: rtCamp/action-slack-notify@v2 diff --git a/.upgrade-config.yml b/.upgrade-config.yml new file mode 100644 index 00000000..c247cdd0 --- /dev/null +++ b/.upgrade-config.yml @@ -0,0 +1,8 @@ +# WARNING: This file was build based on https://github.com/pulumi/ci-mgmt +# but it is currently not in sync. Any update must be done manually + +--- +upstream-provider-name: terraform-provider-equinix +remove-plugins: true +pr-reviewers: equinix/governor-devrel-engineering +javaVersion: "v0.9.5" \ No newline at end of file diff --git a/Makefile b/Makefile index 55565858..fd5f49a3 100644 --- a/Makefile +++ b/Makefile @@ -25,34 +25,13 @@ WORKING_DIR := $(shell pwd) OS := $(shell uname) EMPTY_TO_AVOID_SED := "" -prepare:: - @if test -z "${NAME}"; then echo "NAME not set"; exit 1; fi - @if test -z "${REPOSITORY}"; then echo "REPOSITORY not set"; exit 1; fi - @if test ! -d "provider/cmd/pulumi-tfgen-x${EMPTY_TO_AVOID_SED}yz"; then "Project already prepared"; exit 1; fi - - mv "provider/cmd/pulumi-tfgen-x${EMPTY_TO_AVOID_SED}yz" provider/cmd/pulumi-tfgen-${NAME} - mv "provider/cmd/pulumi-resource-x${EMPTY_TO_AVOID_SED}yz" provider/cmd/pulumi-resource-${NAME} - - if [[ "${OS}" != "Darwin" ]]; then \ - sed -i 's,github.com/pulumi/pulumi-equinix,${REPOSITORY},g' provider/go.mod; \ - find ./ ! -path './.git/*' -type f -exec sed -i 's/[x]yz/${NAME}/g' {} \; &> /dev/null; \ - fi - - # In MacOS the -i parameter needs an empty string to execute in place. - if [[ "${OS}" == "Darwin" ]]; then \ - sed -i '' 's,github.com/pulumi/pulumi-equinix,${REPOSITORY},g' provider/go.mod; \ - find ./ ! -path './.git/*' -type f -exec sed -i '' 's/[x]yz/${NAME}/g' {} \; &> /dev/null; \ - fi - -.PHONY: development provider build_sdks build_nodejs build_dotnet build_go build_python build_java clean cleanup - -development:: install_plugins provider lint_provider build_sdks install_sdks cleanup # Build the provider & SDKs for a development environment +development: install_plugins provider lint_provider build_sdks install_sdks cleanup # Build the provider & SDKs for a development environment # Required for the codegen action that runs in pulumi/pulumi and pulumi/pulumi-terraform-bridge -build:: install_plugins provider build_sdks install_sdks -only_build:: build +build: install_plugins provider build_sdks install_sdks +only_build: build -tfgen:: install_plugins +tfgen: install_plugins upstream (cd provider && go build -o $(WORKING_DIR)/bin/${TFGEN} -ldflags "-X ${PROJECT}/${VERSION_PATH}=${VERSION}" ${PROJECT}/${PROVIDER_PATH}/cmd/${TFGEN}) $(WORKING_DIR)/bin/${TFGEN} schema --out provider/cmd/${PROVIDER} (cd provider && VERSION=$(VERSION) go generate cmd/${PROVIDER}/main.go) @@ -60,16 +39,16 @@ tfgen:: install_plugins bin/pulumi-java-gen: pulumictl download-binary -n pulumi-language-java -v $(JAVA_GEN_VERSION) -r pulumi/pulumi-java -provider:: tfgen install_plugins # build the provider binary +provider: tfgen install_plugins # build the provider binary (cd provider && go build -o $(WORKING_DIR)/bin/${PROVIDER} -ldflags "-X ${PROJECT}/${VERSION_PATH}=${VERSION}" ${PROJECT}/${PROVIDER_PATH}/cmd/${PROVIDER}) -build_sdks:: install_plugins provider build_nodejs build_python build_go build_dotnet build_java # build all the sdks +build_sdks: build_nodejs build_python build_go build_dotnet build_java # build all the sdks -build_nodejs:: VERSION := $(shell pulumictl get version --language javascript) -build_nodejs:: install_plugins tfgen # build the node sdk +build_nodejs: VERSION := $(shell pulumictl get version --language javascript) +build_nodejs: upstream $(WORKING_DIR)/bin/$(TFGEN) nodejs --overlays provider/overlays/nodejs --out sdk/nodejs/ -build_nodejs:: patch_nodejs # fix generated files -build_nodejs:: +build_nodejs: patch_nodejs # fix generated files +build_nodejs: cd sdk/nodejs/ && \ printf "module fake_nodejs_module // Exclude this directory from Go tools\n\ngo 1.17\n" > go.mod && \ yarn install && \ @@ -77,7 +56,7 @@ build_nodejs:: cp ../../README.md ../../LICENSE package.json yarn.lock ./bin/ && \ sed -i.bak -e "s/\$${VERSION}/$(VERSION)/g" ./bin/package.json -patch_nodejs:: +patch_nodejs: echo "patch_nodejs: find and replace wrong imports in examples" && \ find ./sdk/nodejs/ -type f -name "*.ts" -not \( -path "*/bin/*" -o -path "*/node_modules/*" -o -path "*/@types/*" \) -print -exec sed -i.bak 's/import \* as ${PACK} from "@pulumi\/${PACK}"/import \* as ${PACK} from "@${ORG}-labs\/${NODE_PACK}"/g; s/import \* as ${NODE_PACK_ALIAS} from "@${ORG}\/${NODE_PACK}"/import \* as ${PACK} from "@${ORG}-labs\/${NODE_PACK}"/g' {} \; echo "patch_nodejs: delete duplicate imports in examples" && \ @@ -85,8 +64,9 @@ patch_nodejs:: echo "patch_nodejs: remove backup files" && \ find ./sdk/nodejs/ -type f -name "*.ts.bak" -not \( -path "*/bin/*" -o -path "*/node_modules/*" -o -path "*/@types/*" \) -print -exec /bin/rm {} \; -build_python:: PYPI_VERSION := $(shell pulumictl get version --language python) -build_python:: install_plugins tfgen # build the python sdk +build_python: PYPI_VERSION := $(shell pulumictl get version --language python) +build_python: upstream + rm -rf sdk/python/ $(WORKING_DIR)/bin/$(TFGEN) python --overlays provider/overlays/python --out sdk/python/ cd sdk/python/ && \ printf "module fake_python_module // Exclude this directory from Go tools\n\ngo 1.17\n" > go.mod && \ @@ -97,8 +77,8 @@ build_python:: install_plugins tfgen # build the python sdk rm ./bin/setup.py.bak && \ cd ./bin && python3 setup.py build sdist -build_dotnet:: DOTNET_VERSION := $(shell pulumictl get version --language dotnet) -build_dotnet:: install_plugins tfgen # build the dotnet sdk +build_dotnet: DOTNET_VERSION := $(shell pulumictl get version --language dotnet) +build_dotnet: upstream pulumictl get version --language dotnet $(WORKING_DIR)/bin/$(TFGEN) dotnet --overlays provider/overlays/dotnet --out sdk/dotnet/ cd sdk/dotnet/ && \ @@ -106,19 +86,19 @@ build_dotnet:: install_plugins tfgen # build the dotnet sdk echo "${DOTNET_VERSION}" >version.txt && \ dotnet build /p:Version=${DOTNET_VERSION} -build_go:: install_plugins tfgen # build the go sdk +build_go:: upstream $(WORKING_DIR)/bin/$(TFGEN) go --overlays provider/overlays/go --out sdk/go/ -build_java:: PACKAGE_VERSION := $(shell pulumictl get version --language generic) -build_java:: install_plugins tfgen bin/pulumi-java-gen patch_java_schema # build the java sdk +build_java: PACKAGE_VERSION := $(shell pulumictl get version --language generic) +build_java: bin/pulumi-java-gen patch_java_schema upstream $(WORKING_DIR)/bin/$(JAVA_GEN) generate --schema provider/cmd/$(PROVIDER)/schema-java.json --out sdk/java --build gradle-nexus rm -f ./provider/cmd/$(PROVIDER)/schema-java.json -build_java:: patch_java +build_java: patch_java cd sdk/java/ && \ printf "module fake_java_module // Exclude this directory from Go tools\n\ngo 1.17\n" > go.mod && \ gradle --console=plain build -patch_java_schema:: +patch_java_schema: echo "patch_java_schema: copy schema.json to schema-java.json " && \ cp provider/cmd/$(PROVIDER)/schema.json provider/cmd/$(PROVIDER)/schema-java.json echo "patch_java_schema: update schema-java.json to generate the SDK with pulumi as root package" && \ @@ -130,7 +110,7 @@ patch_java_schema:: -e 's/equinix:networkedge/pulumi:networkedge/g' ./provider/cmd/$(PROVIDER)/schema-java.json && \ rm -f ./provider/cmd/$(PROVIDER)/schema-java.json.bak -patch_java:: +patch_java: echo "patch_java: find and replace invocations of pulumi:fabric/metal/networkedge" && \ find ./sdk/java/src/main/java/com/equinix/pulumi -type f -name "*.java" -print -exec sed -i.bak 's/pulumi:fabric/equinix:fabric/g; s/pulumi:metal/equinix:metal/g; s/pulumi:networkedge/equinix:networkedge/g' {} \; echo "patch_java: remove backup files" && \ @@ -157,41 +137,41 @@ patch_java:: sed -i.bak -E '/inceptionYear/,/packaging/s/(name = ).*/\1"$(PACK)"/' ./build.gradle && \ rm -f build.gradle.bak -lint_provider:: provider # lint the provider code +lint_provider: provider # lint the provider code cd provider && golangci-lint run -c ../.golangci.yml -cleanup:: # cleans up the temporary directory +cleanup: # cleans up the temporary directory rm -r $(WORKING_DIR)/bin rm -f provider/cmd/${PROVIDER}/schema.go -help:: +help: @grep '^[^.#]\+:\s\+.*#' Makefile | \ sed "s/\(.\+\):\s*\(.*\) #\s*\(.*\)/`printf "\033[93m"`\1`printf "\033[0m"` \3 [\2]/" | \ expand -t20 -clean:: +clean: rm -rf sdk/{dotnet,nodejs,go,python,java} -install_plugins:: - [ -x $(shell which pulumi) ] || curl -fsSL https://get.pulumi.com | sh - pulumi plugin install resource random 4.3.1 +install_plugins: .pulumi/bin/pulumi + .pulumi/bin/pulumi plugin install resource tls 4.11.0 + .pulumi/bin/pulumi plugin install resource random 4.14.0 -install_dotnet_sdk:: +install_dotnet_sdk: mkdir -p $(WORKING_DIR)/nuget find . -name '*.nupkg' -print -exec cp -p {} ${WORKING_DIR}/nuget \; -install_python_sdk:: +install_python_sdk: -install_go_sdk:: +install_go_sdk: install_java_sdk: -install_nodejs_sdk:: +install_nodejs_sdk: yarn link --cwd $(WORKING_DIR)/sdk/nodejs/bin -install_sdks:: install_dotnet_sdk install_python_sdk install_nodejs_sdk install_java_sdk +install_sdks: install_dotnet_sdk install_python_sdk install_nodejs_sdk install_java_sdk -test:: +test: cd examples && go test -v -tags=all -parallel ${TESTPARALLELISM} -timeout 2h test_provider: @@ -199,3 +179,24 @@ test_provider: @echo "== test_provider ===================================================================" @echo "" cd provider && go test -v -short ./... -parallel $(TESTPARALLELISM) + +upstream: +ifneq ("$(wildcard upstream)","") + scripts/upstream.sh "$@" apply +endif + +upstream.finalize: + scripts/upstream.sh "$@" end_rebase + +upstream.rebase: + scripts/upstream.sh "$@" start_rebase + +.pulumi/bin/pulumi: .pulumi/version + curl -fsSL https://get.pulumi.com | HOME=$(WORKING_DIR) sh -s -- --version $(cat .pulumi/version) + +# Compute the version of Pulumi to use by inspecting the Go dependencies of the provider. +.pulumi/version: + @mkdir -p .pulumi + @cd provider && go list -f "{{slice .Version 1}}" -m github.com/pulumi/pulumi/pkg/v3 | tee ../$@ + +.PHONY: development build build_sdks install_go_sdk install_java_sdk install_python_sdk install_sdks only_build build_dotnet build_go build_java build_nodejs build_python clean cleanup help install_dotnet_sdk install_nodejs_sdk install_plugins lint_provider provider test tfgen upstream upstream.finalize upstream.rebase test_provider diff --git a/go.work.sum b/go.work.sum index 784b7896..73ae22ae 100644 --- a/go.work.sum +++ b/go.work.sum @@ -128,6 +128,7 @@ github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfE github.com/google/pprof v0.0.0-20230406165453-00490a63f317/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk= github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c= github.com/gruntwork-io/terratest v0.43.0/go.mod h1:vZO4J6UW023NDvl1vI+twZk9r//+QEaNT6MfkheH7z0= +github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 h1:1/D3zfFHttUKaCaGKZ/dR2roBXv0vKbSCnssIldfQdI= github.com/hinshun/vt10x v0.0.0-20220301184237-5011da428d02/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68= github.com/ijc/Gotty v0.0.0-20170406111628-a8b993ba6abd/go.mod h1:3LVOLeyx9XVvwPgrt2be44XgSqndprz1G18rSk8KD84= github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a/go.mod h1:yL958EeXv8Ylng6IfnvG4oflryUi3vgA3xPs9hmII1s= diff --git a/patches/README.md b/patches/README.md new file mode 100644 index 00000000..e69de29b diff --git a/provider/go.mod b/provider/go.mod index aa455e8b..aaaa2b19 100644 --- a/provider/go.mod +++ b/provider/go.mod @@ -2,7 +2,11 @@ module github.com/equinix/pulumi-equinix/provider go 1.21 -replace github.com/hashicorp/terraform-plugin-sdk/v2 => github.com/pulumi/terraform-plugin-sdk/v2 v2.0.0-20230912190043-e6d96b3b8f7e +replace ( + github.com/hashicorp/go-cty => github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 + github.com/hashicorp/terraform-plugin-sdk/v2 => github.com/pulumi/terraform-plugin-sdk/v2 v2.0.0-20230912190043-e6d96b3b8f7e + github.com/equinix/terraform-provider-equinix => ../upstream +) require ( github.com/equinix/terraform-provider-equinix v1.18.0 diff --git a/provider/resources.go b/provider/resources.go index 28695290..c14a7b4e 100644 --- a/provider/resources.go +++ b/provider/resources.go @@ -119,6 +119,8 @@ func Provider() tfbridge.ProviderInfo { // The GitHub Org for the provider - defaults to `terraform-providers`. Note that this // should match the TF provider module's require directive, not any replace directives. GitHubOrg: "equinix", + UpstreamRepoPath: "./upstream", + Version: version.Version, Config: map[string]*tfbridge.SchemaInfo{}, PreConfigureCallback: preConfigureCallback, // IgnoreMappings is a list of TF resources and data sources to ignore in mappings errors diff --git a/scripts/upstream.sh b/scripts/upstream.sh new file mode 100644 index 00000000..798cbe4f --- /dev/null +++ b/scripts/upstream.sh @@ -0,0 +1,203 @@ +#!/usr/bin/env bash +# WARNING: This file was build based on https://github.com/pulumi/ci-mgmt +# but it is currently not in sync. Any update must be done manually + +set -e + +# "$1" is the current make command being run. +# It is used to make the error message more actionable. +err_rebase_in_progress() { + cat <