diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..c93853b --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,67 @@ +ARG UBUNTU_VERSION=latest +FROM ubuntu:${UBUNTU_VERSION} + +# Update apt-get and install various needed utilities +RUN apt-get update && \ + apt-get install -y curl && \ + apt-get install -y wget && \ + apt-get install -y xz-utils && \ + apt-get install -y make && \ + apt-get install -y gcc && \ + apt-get install -y git + +# Install bridged provider prerequisites +# See README.md + +# Install go +ARG GO_VERSION=1.18.3 +RUN rm -rf /usr/local/go && \ + wget -O ${GO_VERSION}.tar.gz https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz && \ + tar -C /usr/local -xzf ${GO_VERSION}.tar.gz && \ + rm ${GO_VERSION}.tar.gz + +ENV GOPATH=/root/go +ENV PATH=$PATH:/usr/local/go/bin + +# Install go linter +RUN mkdir -p $GOPATH/bin && \ + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $GOPATH/bin v1.46.2 + +ENV PATH=$PATH:$GOPATH/bin + +# Install pulumictl +ARG PULUMICTL_VERSION=v0.0.32 +RUN rm -rf /usr/local/bin/pulumictl && \ + wget -O pulumictl.${PULUMICTL_VERSION}.tar.gz https://github.com/pulumi/pulumictl/releases/download/${PULUMICTL_VERSION}/pulumictl-${PULUMICTL_VERSION}-linux-amd64.tar.gz && \ + tar -C /usr/local/bin -xzf pulumictl.${PULUMICTL_VERSION}.tar.gz + +# Install nodejs +ARG NODEJS_VERSION=v16.16.0 +ARG NODEJS_PKG=node-${NODEJS_VERSION}-linux-x64 +ARG NODEJS_TARBALL=${NODEJS_PKG}.tar.xz +RUN rm -rf /usr/local/node && \ + wget -O ${NODEJS_TARBALL} https://nodejs.org/dist/${NODEJS_VERSION}/${NODEJS_TARBALL} && \ + tar -C /usr/local -xf ${NODEJS_TARBALL} && \ + mv /usr/local/${NODEJS_PKG} /usr/local/node + +ENV PATH=$PATH:/usr/local/node/bin + +# Install yarn +RUN npm install --global yarn + +# Install python and related items +RUN apt-get install -y python3 && \ + apt-get install -y python3-setuptools + +# Install .NET +# https://stackoverflow.com/questions/73753672/a-fatal-error-occurred-the-folder-usr-share-dotnet-host-fxr-does-not-exist +RUN apt-get remove dotnet* && \ + apt-get remove aspnetcore* && \ + apt-get remove netstandard& + +RUN apt-get update && \ + apt-get install dotnet-sdk-6.0 -y + +# Install Pulumi +RUN curl -fsSL https://get.pulumi.com | sh +ENV PATH=$PATH:/root/.pulumi/bin diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..6b9e8cb --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,8 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.202.3/containers/hugo +{ + "name": "TFProvider", + "build": { + "dockerfile": "Dockerfile" + } +} \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..dc5ac87 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,44 @@ +name: lint + +on: + workflow_call: + inputs: {} + pull_request: + branches: + - main + - v* + - feature* + paths-ignore: + - CHANGELOG.md + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + lint: + name: lint + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v3 + - name: Install go + uses: actions/setup-go@v4 + with: + # The versions of golangci-lint and setup-go here cross-depend and need to update together. + go-version: 1.21 + # Either this action or golangci-lint needs to disable the cache + cache: false + - name: disarm go:embed directives to enable lint + continue-on-error: true # this fails if there are no go:embed directives + run: | + git grep -l 'go:embed' -- provider | xargs sed -i 's/go:embed/ goembed/g' + - name: prepare upstream + continue-on-error: true + run: make upstream + - run: cd provider && go mod tidy + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.54.1 + working-directory: provider + skip-pkg-cache: true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ad2e40 --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +.idea +.code +**/vendor/ +.pulumi +**/bin/ +**/obj/ +Pulumi.*.yaml +**/node_modules/ +.DS_Store + +**/command-output/ + +.idea/ +*.iml + +yarn.lock +**/pulumiManifest.go + +ci-scripts +provider/**/schema-embed.json +**/version.txt +**/nuget +**/dist diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..6064a78 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,21 @@ +linters: + enable: + - errcheck + - goconst + - gofmt + - gosec + - govet + - ineffassign + - lll + - megacheck + - misspell + - nakedret + - revive + - unconvert + - unused + enable-all: false +run: + skip-files: + - schema.go + - pulumiManifest.go + timeout: 20m diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..97babf5 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ +CHANGELOG +========= + +## HEAD (Unreleased) +pulumi-package-publisher +* Use [Pulumi Package Publisher Action](https://github.com/pulumi/pulumi-package-publisher) in release.yml template +* fix dotnetversion typo in release template #94 +* fix `/usr/share/dotnet/host/xfr does not exist` issue when running `make build_dotnet` + +--- diff --git a/CODE-OF-CONDUCT.md b/CODE-OF-CONDUCT.md new file mode 100644 index 0000000..bfb1c21 --- /dev/null +++ b/CODE-OF-CONDUCT.md @@ -0,0 +1,73 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +education, socio-economic status, nationality, personal appearance, race, +religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at code-of-conduct@pulumi.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..eea090e --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,36 @@ +# Contributing to the Pulumi ecosystem + +Do you want to contribute to Pulumi? Awesome! We are so happy to have you. +We have a few tips and housekeeping items to help you get up and running. + +## Code of Conduct + +Please make sure to read and observe our [Code of Conduct](./CODE-OF-CONDUCT.md) + +## Community Expectations + +Please read about our [contribution guidelines here.](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md#communications) + +## Setting up your development environment + +### Pulumi prerequisites + +Please refer to the [main Pulumi repo](https://github.com/pulumi/pulumi/)'s [CONTRIBUTING.md file]( +https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md#developing) for details on how to get set up with Pulumi. + +## Committing Generated Code + +You must generate and check in the SDKs on each pull request containing a code change, e.g. adding a new resource to `resources.go`. + +1. Run `make build_sdks` from the root of this repository +1. Open a pull request containing all changes +1. *Note:* If a large number of seemingly-unrelated diffs are produced by `make build_sdks` (for example, lots of changes to comments unrelated to the change you are making), ensure that the latest dependencies for the provider are installed by running `go mod tidy` in the `provider/` directory of this repository. + +## Running Integration Tests + +The examples and integration tests in this repository will create and destroy real +cloud resources while running. Before running these tests, make sure that you have +configured access to your cloud provider with Pulumi. + +_TODO: Add any steps you need to take to run integration tests here_ + diff --git a/COPYRIGHT b/COPYRIGHT new file mode 100644 index 0000000..0747078 --- /dev/null +++ b/COPYRIGHT @@ -0,0 +1,11 @@ +Except as otherwise noted below and/or in individual files, this +project is licensed under the Apache License, Version 2.0 (see +LICENSE or ). + +This project is a larger work that combines with software written +by third parties, licensed under their own terms. + +Notably, this larger work combines with the Terraform XYZ Provider, +which is licensed under the Mozilla Public License 2.0 (see + or the project itself at +). diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..706fd51 --- /dev/null +++ b/Makefile @@ -0,0 +1,125 @@ +PROJECT_NAME := xyz Package + +SHELL := /bin/bash +PACK := xyz +ORG := pulumi +PROJECT := github.com/${ORG}/pulumi-${PACK} +NODE_MODULE_NAME := @pulumi/${PACK} +TF_NAME := ${PACK} +PROVIDER_PATH := provider +VERSION_PATH := ${PROVIDER_PATH}/pkg/version.Version + +TFGEN := pulumi-tfgen-${PACK} +PROVIDER := pulumi-resource-${PACK} +VERSION := $(shell pulumictl get version) + +TESTPARALLELISM := 4 + +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-xyz,${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-xyz,${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 cleanup + +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 + +tfgen:: install_plugins + (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) + +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 all the sdks + +build_nodejs:: VERSION := $(shell pulumictl get version --language javascript) +build_nodejs:: install_plugins tfgen # build the node sdk + $(WORKING_DIR)/bin/$(TFGEN) nodejs --overlays provider/overlays/nodejs --out sdk/nodejs/ + cd sdk/nodejs/ && \ + yarn install && \ + yarn run tsc && \ + cp ../../README.md ../../LICENSE package.json yarn.lock ./bin/ && \ + sed -i.bak -e "s/\$${VERSION}/$(VERSION)/g" ./bin/package.json + +build_python:: PYPI_VERSION := $(shell pulumictl get version --language python) +build_python:: install_plugins tfgen # build the python sdk + $(WORKING_DIR)/bin/$(TFGEN) python --overlays provider/overlays/python --out sdk/python/ + cd sdk/python/ && \ + cp ../../README.md . && \ + python3 setup.py clean --all 2>/dev/null && \ + rm -rf ./bin/ ../python.bin/ && cp -R . ../python.bin && mv ../python.bin ./bin && \ + sed -i.bak -e 's/^VERSION = .*/VERSION = "$(PYPI_VERSION)"/g' -e 's/^PLUGIN_VERSION = .*/PLUGIN_VERSION = "$(VERSION)"/g' ./bin/setup.py && \ + 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 + pulumictl get version --language dotnet + $(WORKING_DIR)/bin/$(TFGEN) dotnet --overlays provider/overlays/dotnet --out sdk/dotnet/ + cd sdk/dotnet/ && \ + echo "${DOTNET_VERSION}" >version.txt && \ + dotnet build /p:Version=${DOTNET_VERSION} + +build_go:: install_plugins tfgen # build the go sdk + $(WORKING_DIR)/bin/$(TFGEN) go --overlays provider/overlays/go --out sdk/go/ + +lint_provider:: provider # lint the provider code + cd provider && golangci-lint run -c ../.golangci.yml + +cleanup:: # cleans up the temporary directory + rm -r $(WORKING_DIR)/bin + rm -f provider/cmd/${PROVIDER}/schema.go + +help:: + @grep '^[^.#]\+:\s\+.*#' Makefile | \ + sed "s/\(.\+\):\s*\(.*\) #\s*\(.*\)/`printf "\033[93m"`\1`printf "\033[0m"` \3 [\2]/" | \ + expand -t20 + +clean:: + rm -rf sdk/{dotnet,nodejs,go,python} + +install_plugins:: + [ -x $(shell which pulumi) ] || curl -fsSL https://get.pulumi.com | sh + pulumi plugin install resource random 4.3.1 + +install_dotnet_sdk:: + mkdir -p $(WORKING_DIR)/nuget + find . -name '*.nupkg' -print -exec cp -p {} ${WORKING_DIR}/nuget \; + +install_python_sdk:: + +install_go_sdk:: + +install_nodejs_sdk:: + yarn link --cwd $(WORKING_DIR)/sdk/nodejs/bin + +install_sdks:: install_dotnet_sdk install_python_sdk install_nodejs_sdk + +test:: + cd examples && go test -v -tags=all -parallel ${TESTPARALLELISM} -timeout 2h + diff --git a/README-PROVIDER.md b/README-PROVIDER.md new file mode 100644 index 0000000..fd3567b --- /dev/null +++ b/README-PROVIDER.md @@ -0,0 +1,56 @@ +# Foo Resource Provider + +The Foo Resource Provider lets you manage [Foo](http://example.com) resources. + +## Installing + +This package is available for several languages/platforms: + +### Node.js (JavaScript/TypeScript) + +To use from JavaScript or TypeScript in Node.js, install using either `npm`: + +```bash +npm install @pulumi/foo +``` + +or `yarn`: + +```bash +yarn add @pulumi/foo +``` + +### Python + +To use from Python, install using `pip`: + +```bash +pip install pulumi_foo +``` + +### Go + +To use from Go, use `go get` to grab the latest version of the library: + +```bash +go get github.com/pulumi/pulumi-foo/sdk/go/... +``` + +### .NET + +To use from .NET, install using `dotnet add package`: + +```bash +dotnet add package Pulumi.Foo +``` + +## Configuration + +The following configuration points are available for the `foo` provider: + +- `foo:apiKey` (environment: `FOO_API_KEY`) - the API key for `foo` +- `foo:region` (environment: `FOO_REGION`) - the region in which to deploy resources + +## Reference + +For detailed reference documentation, please visit [the Pulumi registry](https://www.pulumi.com/registry/packages/foo/api-docs/). diff --git a/README.md b/README.md new file mode 100644 index 0000000..a38f41b --- /dev/null +++ b/README.md @@ -0,0 +1,458 @@ +# Terraform Bridge Provider Boilerplate + +This repository contains boilerplate code for building a new Pulumi provider which wraps an existing Terraform provider. + +## Background + +This repository is part of the [guide for authoring and publishing a Pulumi Package](https://www.pulumi.com/docs/guides/pulumi-packages/how-to-author). + +Learn about the concepts behind [Pulumi Packages](https://www.pulumi.com/docs/guides/pulumi-packages/#pulumi-packages). + +## Creating a Pulumi Terraform Bridge Provider + +The following instructions cover: + +- providers maintained by Pulumi (denoted with a "Pulumi Official" checkmark on the Pulumi registry) +- providers published and maintained by the Pulumi community, referred to as "third-party" providers + +We showcase a Pulumi-owned provider based on an upstream provider named `terraform-provider-foo`. Substitute appropriate values below for your use case. + +> Note: If the name of the desired Pulumi provider differs from the name of the Terraform provider, you will need to carefully distinguish between the references - see for an example. + +### Prerequisites + +Ensure the following tools are installed and present in your `$PATH`: + +- [`pulumictl`](https://github.com/pulumi/pulumictl#installation) +- [Go 1.17](https://golang.org/dl/) or 1.latest +- [NodeJS](https://nodejs.org/en/) 14.x. We recommend using [nvm](https://github.com/nvm-sh/nvm) to manage NodeJS installations. +- [Yarn](https://yarnpkg.com/) +- [TypeScript](https://www.typescriptlang.org/) +- [Python](https://www.python.org/downloads/) (called as `python3`). For recent versions of MacOS, the system-installed version is fine. +- [.NET](https://dotnet.microsoft.com/download) + +### Creating and Initializing the Repository + +Pulumi offers this repository as a [GitHub template repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template) for convenience. From this repository: + +1. Click "Use this template". +1. Set the following options: + - Owner: pulumi (third-party: your GitHub organization/username) + - Repository name: pulumi-foo (third-party: preface your repo name with "pulumi" as standard practice) + - Description: Pulumi provider for Foo + - Repository type: Public +1. Clone the generated repository. + +From the templated repository: + +1. Run the following command to update files to use the name of your provider (third-party: use your GitHub organization/username): + + ```bash + make prepare NAME=foo REPOSITORY=github.com/pulumi/pulumi-foo + ``` + + This will do the following: + - rename folders in `provider/cmd` to `pulumi-resource-foo` and `pulumi-tfgen-foo` + - replace dependencies in `provider/go.mod` to reflect your repository name + - find and replace all instances of the boilerplate `xyz` with the `NAME` of your provider. + + Note for third-party providers: + - Make sure to set the correct GitHub organization/username in all files referencing your provider as a dependency: + - `examples/go.mod` + - `provider/resources.go` + - `sdk/go.mod` + - `provider/cmd/pulumi-resource-foo/main.go` + - `provider/cmd/pulumi-tfgen-foo/main.go` + +2. Modify `README-PROVIDER.md` to include the following (we'll rename it to `README.md` toward the end of this guide): + - Any desired build status badges. + - An introductory paragraph describing the type of resources the provider manages, e.g. "The Foo provider for Pulumi manages resources for [Foo](http://example.com/). + - In the "Installing" section, correct package names for the various SDK libraries in the languages Pulumi supports. + - In the "Configuration" section, any configurable options for the provider. These may include, but are not limited to, environment variables or options that can be set via [`pulumi config set`](https://www.pulumi.com/docs/reference/cli/pulumi_config_set/). + - In the "Reference" section, provide a link to the to-be-published documentation. + - Feel free to refer to [the Pulumi AWS provider README](https://github.com/pulumi/pulumi-aws) as an example. + +### Composing the Provider Code - Prerequisites + +Pulumi provider repositories have the following general structure: + +- `examples/` contains sample code which may optionally be included as integration tests to be run as part of a CI/CD pipeline. +- `provider/` contains the Go code used to create the provider as well as generate the SDKs in the various languages that Pulumi supports. + - `provider/cmd/pulumi-tfgen-foo` generates the Pulumi resource schema (`schema.json`), based on the Terraform provider's resources. + - `provider/cmd/pulumi-resource-foo` generates the SDKs in all supported languages from the schema, placing them in the `sdk/` folder. + - `provider/pkg/resources.go` is the location where we will define the Terraform-to-Pulumi mappings for resources. +- `sdk/` contains the generated SDK code for each of the language platforms that Pulumi supports, with each supported platform in a separate subfolder. + +1. In `provider/go.mod`, add a reference to the upstream Terraform provider in the `require` section, e.g. + + ```go + github.com/foo/terraform-provider-foo v0.4.0 + ``` + +1. In `provider/resources.go`, ensure the reference in the `import` section uses the correct Go module path, e.g.: + + ```go + github.com/foo/terraform-provider-foo/foo + ``` + +1. Download the dependencies: + + ```bash + cd provider && go mod tidy && cd - + ``` + +1. Create the schema by running the following command: + + ```bash + make tfgen + ``` + + Note warnings about unmapped resources and data sources in the command's output. We map these in the next section, e.g.: + + ```text + warning: resource foo_something not found in provider map; skipping + warning: resource foo_something_else not found in provider map; skipping + warning: data source foo_something not found in provider map; skipping + warning: data source foo_something_else not found in provider map; skipping + ``` + +## Adding Mappings, Building the Provider and SDKs + +In this section we will add the mappings that allow the interoperation between the Pulumi provider and the Terraform provider. Terraform resources map to an identically named concept in Pulumi. Terraform data sources map to plain old functions in your supported programming language of choice. Pulumi also allows provider functions and resources to be grouped into _namespaces_ to improve the cohesion of a provider's code, thereby making it easier for developers to use. If your provider has a large number of resources, consider using namespaces to improve usability. + +The following instructions all pertain to `provider/resources.go`, in the section of the code where we construct a `tfbridge.ProviderInfo` object: + +1. **Add resource mappings:** For each resource in the provider, add an entry in the `Resources` property of the `tfbridge.ProviderInfo`, e.g.: + + ```go + // Most providers will have all resources (and data sources) in the main module. + // Note the mapping from snake_case HCL naming conventions to UpperCamelCase Pulumi SDK naming conventions. + // The name of the provider is omitted from the mapped name due to the presence of namespaces in all supported Pulumi languages. + "foo_something": {Tok: tfbridge.MakeResource(mainPkg, mainMod, "Something")}, + "foo_something_else": {Tok: tfbridge.MakeResource(mainPkg, mainMod, "SomethingElse")}, + ``` + +1. **Add CSharpName (if necessary):** Dotnet does not allow for fields named the same as the enclosing type, which sometimes results in errors during the dotnet SDK build. + If you see something like + + ```text + error CS0542: 'ApiKey': member names cannot be the same as their enclosing type [/Users/guin/go/src/github.com/pulumi/pulumi-artifactory/sdk/dotnet/Pulumi.Artifactory.csproj] + ``` + + you'll want to give your Resource a CSharpName, which can have any value that makes sense: + + ```go + "foo_something_dotnet": { + Tok: tfbridge.MakeResource(mainPkg, mainMod, "SomethingDotnet"), + Fields: map[string]*tfbridge.SchemaInfo{ + "something_dotnet": { + CSharpName: "SpecialName", + }, + }, + }, + ``` + + [See the underlying terraform-bridge code here.](https://github.com/pulumi/pulumi-terraform-bridge/blob/master/pkg/tfbridge/info.go#L168) +1. **Add data source mappings:** For each data source in the provider, add an entry in the `DataSources` property of the `tfbridge.ProviderInfo`, e.g.: + + ```go + // Note the 'get' prefix for data sources + "foo_something": {Tok: tfbridge.MakeDataSource(mainPkg, mainMod, "getSomething")}, + "foo_something_else": {Tok: tfbridge.MakeDataSource(mainPkg, mainMod, "getSomethingElse")}, + ``` + +1. **Add documentation mapping (sometimes needed):** If the upstream provider's repo is not a part of the `terraform-providers` GitHub organization, specify the `GitHubOrg` property of `tfbridge.ProviderInfo` to ensure that documentation is picked up by the codegen process, and that attribution for the upstream provider is correct, e.g.: + + ```go + GitHubOrg: "foo", + ``` + +1. **Add provider configuration overrides (not typically needed):** Pulumi's Terraform bridge automatically detects configuration options for the upstream provider. However, in rare cases these settings may need to be overridden, e.g. if we want to change an environment variable default from `API_KEY` to `FOO_API_KEY`. Examples of common uses cases: + + ```go + "additional_required_parameter": {}, + "additional_optional_string_parameter": { + Default: &tfbridge.DefaultInfo{ + Value: "default_value", + }, + "additional_optional_boolean_parameter": { + Default: &tfbridge.DefaultInfo{ + Value: true, + }, + // Renamed environment variables can be accounted for like so: + "apikey": { + Default: &tfbridge.DefaultInfo{ + EnvVars: []string{"FOO_API_KEY"}, + }, + ``` + +1. Build the provider binary and ensure there are no warnings about unmapped resources and no warnings about unmapped data sources: + + ```bash + make provider + ``` + + You may see warnings about documentation and examples, including "unexpected code snippets". These can be safely ignored for now. Pulumi will add additional documentation on mapping docs in a future revision of this guide. + +1. Build the SDKs in the various languages Pulumi supports: + + ```bash + make build_sdks + ``` + +1. Ensure the Golang SDK is a proper go module: + + ```bash + cd sdk && go mod tidy && cd - + ``` + + This will pull in the correct dependencies in `sdk/go.mod` as well as setting the dependency tree in `sdk/go.sum`. + +1. Finally, ensure the provider code conforms to Go standards: + + ```bash + make lint_provider + ``` + + Fix any issues found by the linter. + +**Note:** If you make revisions to code in `resources.go`, you must re-run the `make tfgen` target to regenerate the schema. +The `make tfgen` target will take the file `schema.json` and serialize it to a byte array so that it can be included in the build output. +(This is a holdover from Go 1.16, which does not have the ability to directly embed text files. We are working on removing the need for this step.) + +## Sample Program + +In this section, we will create a Pulumi program in TypeScript that utilizes the provider we created to ensure everything is working properly. + +1. Create an account with the provider's service and generate any necessary credentials, e.g. API keys. + - Email: bot@pulumi.com + - Password: (Create a random password in 1Password with the maximum length and complexity allowed by the provider.) + - Ensure all secrets (passwords, generated API keys) are stored in Pulumi's 1Password vault. + +1. Copy the `pulumi-resource-foo` binary generated by `make provider` and place it in your `$PATH` (`$GOPATH/bin` is a convenient choice), e.g.: + + ```bash + cp bin/pulumi-resource-foo $GOPATH/bin + ``` + +1. Tell Yarn to use your local copy of the SDK: + + ```bash + make install_nodejs_sdk + ``` + +1. Create a new Pulumi program in the `examples/` directory, e.g.: + + ```bash + mkdir examples/my-example/ts # Change "my-example" to something more meaningful. + cd examples/my-example/ts + pulumi new typescript + # (Go through the prompts with the default values) + npm install + yarn link @pulumi/foo + ``` + +1. Create a minimal program for the provider, i.e. one that creates the smallest-footprint resource. Place this code in `index.ts`. +1. Configure any necessary environment variables for authentication, e.g `$FOO_USERNAME`, `$FOO_TOKEN`, in your local environment. +1. Ensure the program runs successfully via `pulumi up`. +1. Once the program completes successfully, verify the resource was created in the provider's UI. +1. Destroy any resources created by the program via `pulumi destroy`. + +Optionally, you may create additional examples for SDKs in other languages supported by Pulumi: + +1. Python: + + ```bash + mkdir examples/my-example/py + cd examples/my-example/py + pulumi new python + # (Go through the prompts with the default values) + source venv/bin/activate # use the virtual Python env that Pulumi sets up for you + pip install pulumi_foo + ``` + +1. Follow the steps above to verify the program runs successfully. + +## Add End-to-end Testing + +We can run integration tests on our examples using the `*_test.go` files in the `examples/` folder. + +1. Add code to `examples_nodejs_test.go` to call the example you created, e.g.: + + ```go + // Swap out MyExample and "my-example" below with the name of your integration test. + func TestAccMyExampleTs(t *testing.T) { + test := getJSBaseOptions(t). + With(integration.ProgramTestOptions{ + Dir: filepath.Join(getCwd(t), "my-example", "ts"), + }) + integration.ProgramTest(t, &test) + } + ``` + +1. Add a similar function for each example that you want to run in an integration test. For examples written in other languages, create similar files for `examples_${LANGUAGE}_test.go`. + +1. You can run these tests locally via Make: + + ```bash + make test + ``` + + You can also run each test file separately via test tags: + + ```bash + cd examples && go test -v -tags=nodejs + ``` + +## Configuring CI with GitHub Actions + +### Third-party providers + +1. Follow the instructions laid out in the [deployment templates](./deployment-templates/README-DEPLOYMENT.md). + +### Pulumi Internal + +In this section, we'll add the necessary configuration to work with GitHub Actions for Pulumi's standard CI/CD workflows for providers. + +1. Generate GitHub workflows per [the instructions in the ci-mgmt repository](https://github.com/pulumi/ci-mgmt/) and copy to `.github/` in this repository. + +1. Ensure that any required secrets are present as repository-level [secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) in GitHub. These will be used by the integration tests during the CI/CD process. + +1. Repository settings: Toggle `Allow auto-merge` on in your provider repo to automate GitHub Actions workflow updates. + +## Final Steps + +1. Ensure all required configurations (API keys, etc.) are documented in README-PROVIDER.md. + +1. Replace this file with the README for the provider and push your changes: + + ```bash + mv README-PROVIDER.md README.md + ``` + +1. If publishing the npm package fails during the "Publish SDKs" Action, perform the following steps: + 1. Go to [NPM Packages](https://www.npmjs.com/) and sign in as pulumi-bot. + 1. Click on the bot's profile pic and navigate to "Packages". + 1. On the left, under "Organizations, click on the Pulumi organization. + 1. On the last page of the listed packages, you should see the new package. + 1. Under "Settings", set the Package Status to "public". + +Now you are ready to use the provider, cut releases, and have some well-deserved :ice_cream:! + +## Building the Provider Locally + +There are 2 ways the provider can be built locally: + +`make provider` will use the current operating system and architecture to create a binary that can be used on your PATH. + +To build the provider for another set of operating systems / architectures, the project uses [goreleaser](https://goreleaser.com/). +Goreleaser, a CLI tool, that allows a user to build a matrix of binaries. + +Create a `.goreleaser.yml` file in the root of your project: + +```yaml + +archives: +- id: archive + name_template: "{{ .Binary }}-{{ .Tag }}-{{ .Os }}-{{ .Arch }}" +before: + hooks: + - make tfgen +builds: +- binary: pulumi-resource-xyz + dir: provider + goarch: + - amd64 + - arm64 + goos: + - darwin + - windows + - linux + ignore: [] + ldflags: + - -X github.com/pulumi/pulumi-xyz/provider/pkg/version.Version={{.Tag}} + main: ./cmd/pulumi-resource-xyz/ + sort: asc + use: git +release: + disable: false +snapshot: + name_template: "{{ .Tag }}-SNAPSHOT" +``` + +To build the provider for the combination of architectures and operating systems, you can run the following CLI command: + +```bash +goreleaser build --rm-dist --skip-validate +``` + +That will ensure that a list of binaries are available to use: + +```bash + +▶ tree dist +dist +├── CHANGELOG.md +├── artifacts.json +├── config.yaml +├── metadata.json +├── pulumi-xyz_darwin_amd64_v1 +│ └── pulumi-resource-xyz +├── pulumi-xyz_darwin_arm64 +│ └── pulumi-resource-xyz +├── pulumi-xyz_linux_amd64_v1 +│ └── pulumi-resource-xyz +├── pulumi-xyz_linux_arm64 +│ └── pulumi-resource-xyz +├── pulumi-xyz_windows_amd64_v1 +│ └── pulumi-resource-xyz.exe +└── pulumi-xyz_windows_arm64 + └── pulumi-resource-xyz.exe +``` + +Any of the provider binaries can be used to target the correct machine architecture + +## The Shim Pattern + +If you receive the following error: `use of internal package github.com/example/terraform-provider-example/internal/provider not allowed`, you need to use +the shim model below, and replace the example item: + +```bash + +mkdir -p provider/shim +cat <<-EOF> provider/shim/go.mod +module github.com/example/terraform-provider-example/shim + +go 1.18 + +require github.com/hashicorp/terraform-plugin-sdk/v2 v2.22.0 +require github.com/example/terraform-provider-example v1.0.0 + +EOF + +cat <<-EOF> provider/shim/shim.go +package shim + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/example/terraform-provider-example/internal/provider" +) + +// fix provider.Provider here to match whats in internal/provider +func Provider() *schema.Provider { + return provider.Provider() +} + +EOF + +cd provider/shim/ && go mod tidy && cd ../../ + +cat <> provider/go.mod +replace github.com/example/terraform-provider-example/shim => ./shim +require github.com/example/terraform-provider-example/shim v0.0.0 +EOF + +cd provider && go mod tidy + +``` + \ No newline at end of file diff --git a/deployment-templates/.goreleaser.yml b/deployment-templates/.goreleaser.yml new file mode 100644 index 0000000..9097c9a --- /dev/null +++ b/deployment-templates/.goreleaser.yml @@ -0,0 +1,29 @@ +archives: + - id: archive + name_template: '{{ .Binary }}-{{ .Tag }}-{{ .Os }}-{{ .Arch }}' +before: + hooks: + - make tfgen +builds: + - binary: pulumi-resource-xyz + dir: provider + env: + - CGO_ENABLED=0 + goarch: + - amd64 + - arm64 + goos: + - darwin + - windows + - linux + ldflags: + # The line below MUST align with the module in current provider/go.mod + - -X github.com/your-org-name/pulumi-xyz/provider/pkg/version.Version={{.Tag }} + main: ./cmd/pulumi-resource-xyz/ +changelog: + skip: true +release: + disable: false + prerelease: auto +snapshot: + name_template: '{{ .Tag }}-SNAPSHOT' diff --git a/deployment-templates/README-DEPLOYMENT.md b/deployment-templates/README-DEPLOYMENT.md new file mode 100644 index 0000000..9d6e68b --- /dev/null +++ b/deployment-templates/README-DEPLOYMENT.md @@ -0,0 +1,27 @@ +# Configure + +1. Create a directory at the root of your repo called .github/workflows + +1. Place the release.yml from this directory there + +1. Place the .goreleaser.yml from this directory at the root of your repo + +1. The example shown uses Pulumi's [Publishing Action](https://github.com/pulumi/pulumi-package-publisher) to publish the language SDKS. + Refer to the README for any environment secrets you need to set up. + +1. Customize .goreleaser.yml for your provider, paying special attention that the ldlflags are set to match your provider/go.mod exactly: + + `-X github.com/pulumi/pulumi-aws/provider/v5/pkg/version.Version={{.Tag}}` + +1. Delete this directory if desired + + +# Deploy + +1. Push a tag to your repo in the format "v0.0.0" to initiate a release + +1. IMPORTANT: also add a tag in the format "sdk/v0.0.0" for the Go SDK + +# Upgrade + +Pulumi provides a [GitHub action](https://github.com/pulumi/pulumi-upgrade-provider-action) to automate upgrading your provider upon a new upstream version release. An example workflow that runs the upgrade action on a cron job, as well as whenever an issue is created with a title prefix of 'Upgrade terraform-provider', is [provided here](./upgrade-provider.yml). diff --git a/deployment-templates/release.yml b/deployment-templates/release.yml new file mode 100644 index 0000000..2919255 --- /dev/null +++ b/deployment-templates/release.yml @@ -0,0 +1,79 @@ +name: release +on: + push: + tags: + - v*.*.* +env: + # THIS GITHUB_TOKEN IS A REQUIREMENT TO BE ABLE TO WRITE TO GH RELEASES + GITHUB_TOKEN: ${{ YOUR GITHUB TOKEN HERE }} + # IF YOU NEED TO PUBLISH A NPM PACKAGE THEN ENSURE A NPM_TOKEN SECRET IS SET + # AND PUBLISH_NPM: TRUE. IF YOU WANT TO PUBLISH TO A PRIVATE NPM REGISTRY + # THEN ENSURE THE NPM_REGISTRY_URL IS CHANGED + NODE_AUTH_TOKEN: ${{ YOUR NPM TOKEN HERE }} + NPM_TOKEN: ${{ YOUR NPM TOKEN HERE }} + PUBLISH_NPM: true + NPM_REGISTRY_URL: https://registry.npmjs.org + # IF YOU NEED TO PUBLISH A NUGET PACKAGE THEN ENSURE AN NUGET_PUBLISH_KEY + # SECRET IS SET AND PUBLISH_NUGET: TRUE. IF YOU WANT TO PUBLISH TO AN ALTERNATIVE + # NPM REGISTRY THEN ENSURE THE NPM_REGISTRY_URL IS CHANGED + NUGET_PUBLISH_KEY: ${{ YOUR NUGET PUBLISH KEY HERE }} + NUGET_FEED_URL: https://api.nuget.org/v3/index.json + PUBLISH_NUGET: true + # IF YOU NEED TO PUBLISH A PYPI PACKAGE SET PUBLISH_PYPI: TRUE AND CHANGE PYPI_PASSWORD, PYPI_USERNAME TO YOUR CREDENTIALS. + # IF YOU WANT TO PUBLISH TO AN ALTERNATIVE PYPI REGISTRY THEN ENSURE THE PYPI_REPOSITORY_URL IS SET. + PYPI_PASSWORD: ${{ YOUR PYPI PASSWORD HERE }} + PYPI_USERNAME: "YOUR PYPI USERNAME HERE" + PYPI_REPOSITORY_URL: "" + PUBLISH_PYPI: true +jobs: + publish_binary: + name: publish + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v2 + - name: Unshallow clone for tags + run: git fetch --prune --unshallow --tags + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{matrix.goversion}} + - name: Install pulumictl + uses: jaxxstorm/action-install-gh-release@v1.5.0 + with: + repo: pulumi/pulumictl + - name: Set PreRelease Version + run: echo "GORELEASER_CURRENT_TAG=v$(pulumictl get version --language generic)" >> $GITHUB_ENV + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + args: -p 3 release --rm-dist + version: latest + strategy: + fail-fast: true + matrix: + goversion: + - 1.17.x + publish_sdk: + name: Publish SDKs + runs-on: ubuntu-latest + needs: publish_binary + steps: + - name: Publish SDKs + uses: pulumi/pulumi-package-publisher@v0.0.6 + strategy: + fail-fast: true + matrix: + dotnetversion: + - 3.1.301 + goversion: + - 1.17.x + language: + - nodejs + - python + - dotnet + - go + nodeversion: + - 14.x + pythonversion: + - "3.9" diff --git a/deployment-templates/upgrade-provider.yml b/deployment-templates/upgrade-provider.yml new file mode 100644 index 0000000..acb24d5 --- /dev/null +++ b/deployment-templates/upgrade-provider.yml @@ -0,0 +1,16 @@ +name: Upgrade provider +on: + issues: + types: + - opened + schedule: + - cron: '0 5 * * *' +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +jobs: + upgrade_provider: + name: upgrade-provider + runs-on: ubuntu-latest + steps: + - name: Call upgrade provider action + uses: pulumi/pulumi-upgrade-provider-action@main diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 0000000..ed6aaad --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1,4 @@ +.pulumi/ +**/bin/ +node_modules/ + diff --git a/examples/examples_nodejs_test.go b/examples/examples_nodejs_test.go new file mode 100644 index 0000000..6983bd8 --- /dev/null +++ b/examples/examples_nodejs_test.go @@ -0,0 +1,21 @@ +//go:build nodejs || all +// +build nodejs all + +package examples + +import ( + "testing" + + "github.com/pulumi/pulumi/pkg/v3/testing/integration" +) + +func getJSBaseOptions(t *testing.T) integration.ProgramTestOptions { + base := getBaseOptions() + baseJS := base.With(integration.ProgramTestOptions{ + Dependencies: []string{ + "@pulumi/foo", + }, + }) + + return baseJS +} diff --git a/examples/examples_py_test.go b/examples/examples_py_test.go new file mode 100644 index 0000000..7d832f4 --- /dev/null +++ b/examples/examples_py_test.go @@ -0,0 +1,22 @@ +//go:build python || all +// +build python all + +package examples + +import ( + "path/filepath" + "testing" + + "github.com/pulumi/pulumi/pkg/v3/testing/integration" +) + +func getPythonBaseOptions(t *testing.T) integration.ProgramTestOptions { + base := getBaseOptions() + basePython := base.With(integration.ProgramTestOptions{ + Dependencies: []string{ + filepath.Join("..", "sdk", "python", "bin"), + }, + }) + + return basePython +} diff --git a/examples/examples_test.go b/examples/examples_test.go new file mode 100644 index 0000000..9810e75 --- /dev/null +++ b/examples/examples_test.go @@ -0,0 +1,24 @@ +package examples + +import ( + "os" + "testing" + + "github.com/pulumi/pulumi/pkg/v3/testing/integration" +) + +func getCwd(t *testing.T) string { + cwd, err := os.Getwd() + if err != nil { + t.FailNow() + } + + return cwd +} + +func getBaseOptions() integration.ProgramTestOptions { + return integration.ProgramTestOptions{ + RunUpdateTest: false, + ExpectRefreshChanges: true, + } +} diff --git a/examples/go.mod b/examples/go.mod new file mode 100644 index 0000000..48988cb --- /dev/null +++ b/examples/go.mod @@ -0,0 +1,3 @@ +module github.com/pulumi/pulumi-xyz/examples + +go 1.21 diff --git a/provider/cmd/pulumi-resource-xyz/.gitignore b/provider/cmd/pulumi-resource-xyz/.gitignore new file mode 100644 index 0000000..eaadaff --- /dev/null +++ b/provider/cmd/pulumi-resource-xyz/.gitignore @@ -0,0 +1 @@ +schema.go diff --git a/provider/cmd/pulumi-resource-xyz/bridge-metadata.json b/provider/cmd/pulumi-resource-xyz/bridge-metadata.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/provider/cmd/pulumi-resource-xyz/bridge-metadata.json @@ -0,0 +1 @@ +{} diff --git a/provider/cmd/pulumi-resource-xyz/generate.go b/provider/cmd/pulumi-resource-xyz/generate.go new file mode 100644 index 0000000..414389e --- /dev/null +++ b/provider/cmd/pulumi-resource-xyz/generate.go @@ -0,0 +1,63 @@ +// Copyright 2016-2020, Pulumi Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build ignore + +package main + +import ( + "encoding/json" + "errors" + "io/fs" + "io/ioutil" + "log" + "os" + + "github.com/pulumi/pulumi/pkg/v3/codegen/schema" +) + +func main() { + version, found := os.LookupEnv("VERSION") + if !found { + log.Fatal("version not found") + } + + schemaContents, err := ioutil.ReadFile("./schema.json") + if err != nil { + log.Fatal(err) + } + + var packageSpec schema.PackageSpec + err = json.Unmarshal(schemaContents, &packageSpec) + if err != nil { + log.Fatalf("cannot deserialize schema: %v", err) + } + + packageSpec.Version = version + versionedContents, err := json.Marshal(packageSpec) + if err != nil { + log.Fatalf("cannot reserialize schema: %v", err) + } + + // Clean up schema.go as it may be present & gitignored and tolerate an error if the file isn't present. + err = os.Remove("./schema.go") + if err != nil && !errors.Is(err, fs.ErrNotExist) { + log.Fatal(err) + } + + err = ioutil.WriteFile("./schema-embed.json", versionedContents, 0600) + if err != nil { + log.Fatal(err) + } +} diff --git a/provider/cmd/pulumi-resource-xyz/main.go b/provider/cmd/pulumi-resource-xyz/main.go new file mode 100644 index 0000000..aeed3da --- /dev/null +++ b/provider/cmd/pulumi-resource-xyz/main.go @@ -0,0 +1,33 @@ +// Copyright 2016-2018, Pulumi Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:generate go run ./generate.go + +package main + +import ( + _ "embed" + + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + xyz "github.com/pulumi/pulumi-xyz/provider" + "github.com/pulumi/pulumi-xyz/provider/pkg/version" +) + +//go:embed schema-embed.json +var pulumiSchema []byte + +func main() { + // Modify the path to point to the new provider + tfbridge.Main("xyz", version.Version, xyz.Provider(), pulumiSchema) +} diff --git a/provider/cmd/pulumi-tfgen-xyz/main.go b/provider/cmd/pulumi-tfgen-xyz/main.go new file mode 100644 index 0000000..76648ce --- /dev/null +++ b/provider/cmd/pulumi-tfgen-xyz/main.go @@ -0,0 +1,26 @@ +// Copyright 2016-2018, Pulumi Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen" + xyz "github.com/pulumi/pulumi-xyz/provider" + "github.com/pulumi/pulumi-xyz/provider/pkg/version" +) + +func main() { + // Modify the path to point to the new provider + tfgen.Main("xyz", version.Version, xyz.Provider()) +} diff --git a/provider/go.mod b/provider/go.mod new file mode 100644 index 0000000..7b02eb5 --- /dev/null +++ b/provider/go.mod @@ -0,0 +1,10 @@ +module github.com/pulumi/pulumi-xyz/provider + +go 1.21 + +replace github.com/hashicorp/terraform-plugin-sdk/v2 => github.com/pulumi/terraform-plugin-sdk/v2 v2.0.0-20230912190043-e6d96b3b8f7e + +require ( + github.com/pulumi/pulumi-terraform-bridge/v3 v3.69.0 + github.com/pulumi/pulumi/sdk/v3 v3.98.0 +) diff --git a/provider/pkg/version/version.go b/provider/pkg/version/version.go new file mode 100644 index 0000000..1d17f38 --- /dev/null +++ b/provider/pkg/version/version.go @@ -0,0 +1,18 @@ +// Copyright 2016-2018, Pulumi Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package version + +// Version is initialized by the Go linker to contain the semver of this build. +var Version string diff --git a/provider/resources.go b/provider/resources.go new file mode 100644 index 0000000..ffd44a7 --- /dev/null +++ b/provider/resources.go @@ -0,0 +1,169 @@ +// Copyright 2016-2023, Pulumi Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package xyz + +import ( + "fmt" + "path" + + // Allow embedding bridge-metadata.json in the provider. + _ "embed" + + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/tokens" + shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" + shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" + "github.com/pulumi/pulumi/sdk/v3/go/common/resource" + + // Replace this provider with the provider you are bridging. + xyz "github.com/iwahbe/terraform-provider-xyz/provider" + + "github.com/pulumi/pulumi-xyz/provider/pkg/version" +) + +// all of the token components used below. +const ( + // This variable controls the default name of the package in the package + // registries for nodejs and python: + mainPkg = "xyz" + // modules: + mainMod = "index" // the xyz module +) + +// preConfigureCallback is called before the providerConfigure function of the underlying provider. +// It should validate that the provider can be configured, and provide actionable errors in the case +// it cannot be. Configuration variables can be read from `vars` using the `stringValue` function - +// for example `stringValue(vars, "accessKey")`. +func preConfigureCallback(resource.PropertyMap, shim.ResourceConfig) error { + return nil +} + +//go:embed cmd/pulumi-resource-xyz/bridge-metadata.json +var metadata []byte + +// Provider returns additional overlaid schema and metadata associated with the provider.. +func Provider() tfbridge.ProviderInfo { + // Create a Pulumi provider mapping + prov := tfbridge.ProviderInfo{ + // Instantiate the Terraform provider + P: shimv2.NewProvider(xyz.New(version.Version)()), + Name: "xyz", + // DisplayName is a way to be able to change the casing of the provider + // name when being displayed on the Pulumi registry + DisplayName: "", + // The default publisher for all packages is Pulumi. + // Change this to your personal name (or a company name) that you + // would like to be shown in the Pulumi Registry if this package is published + // there. + Publisher: "Pulumi", + // LogoURL is optional but useful to help identify your package in the Pulumi Registry + // if this package is published there. + // + // You may host a logo on a domain you control or add an SVG logo for your package + // in your repository and use the raw content URL for that file as your logo URL. + LogoURL: "", + // PluginDownloadURL is an optional URL used to download the Provider + // for use in Pulumi programs + // e.g https://github.com/org/pulumi-provider-name/releases/ + PluginDownloadURL: "", + Description: "A Pulumi package for creating and managing xyz cloud resources.", + // category/cloud tag helps with categorizing the package in the Pulumi Registry. + // For all available categories, see `Keywords` in + // https://www.pulumi.com/docs/guides/pulumi-packages/schema/#package. + Keywords: []string{"pulumi", "xyz", "category/cloud"}, + License: "Apache-2.0", + Homepage: "https://www.pulumi.com", + Repository: "https://github.com/pulumi/pulumi-xyz", + // 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: "", + MetadataInfo: tfbridge.NewProviderMetadata(metadata), + Config: map[string]*tfbridge.SchemaInfo{ + // Add any required configuration here, or remove the example below if + // no additional points are required. + // "region": { + // Type: tfbridge.MakeType("region", "Region"), + // Default: &tfbridge.DefaultInfo{ + // EnvVars: []string{"AWS_REGION", "AWS_DEFAULT_REGION"}, + // }, + // }, + }, + PreConfigureCallback: preConfigureCallback, + Resources: map[string]*tfbridge.ResourceInfo{ + // Map each resource in the Terraform provider to a Pulumi type. Two examples + // are below - the single line form is the common case. The multi-line form is + // needed only if you wish to override types or other default options. + // + // "aws_iam_role": {Tok: tfbridge.MakeResource(mainPkg, mainMod, "IamRole")} + // + // "aws_acm_certificate": { + // Tok: tfbridge.MakeResource(mainPkg, mainMod, "Certificate"), + // Fields: map[string]*tfbridge.SchemaInfo{ + // "tags": {Type: tfbridge.MakeType(mainPkg, "Tags")}, + // }, + // }, + }, + DataSources: map[string]*tfbridge.DataSourceInfo{ + // Map each resource in the Terraform provider to a Pulumi function. An example + // is below. + // "aws_ami": {Tok: tfbridge.MakeDataSource(mainPkg, mainMod, "getAmi")}, + }, + JavaScript: &tfbridge.JavaScriptInfo{ + // List any npm dependencies and their versions + Dependencies: map[string]string{ + "@pulumi/pulumi": "^3.0.0", + }, + DevDependencies: map[string]string{ + "@types/node": "^10.0.0", // so we can access strongly typed node definitions. + "@types/mime": "^2.0.0", + }, + // See the documentation for tfbridge.OverlayInfo for how to lay out this + // section, or refer to the AWS provider. Delete this section if there are + // no overlay files. + //Overlay: &tfbridge.OverlayInfo{}, + }, + Python: &tfbridge.PythonInfo{ + // List any Python dependencies and their version ranges + Requires: map[string]string{ + "pulumi": ">=3.0.0,<4.0.0", + }, + }, + Golang: &tfbridge.GolangInfo{ + ImportBasePath: path.Join( + fmt.Sprintf("github.com/pulumi/pulumi-%[1]s/sdk/", mainPkg), + tfbridge.GetModuleMajorVersion(version.Version), + "go", + mainPkg, + ), + GenerateResourceContainerTypes: true, + }, + CSharp: &tfbridge.CSharpInfo{ + PackageReferences: map[string]string{ + "Pulumi": "3.*", + }, + }, + } + + // These are new API's that you may opt to use to automatically compute resource + // tokens, and apply auto aliasing for full backwards compatibility. For more + // information, please reference: + // https://pkg.go.dev/github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge#ProviderInfo.ComputeTokens + prov.MustComputeTokens(tokens.SingleModule("xyz_", mainMod, + tokens.MakeStandard(mainPkg))) + prov.MustApplyAutoAliases() + prov.SetAutonaming(255, "-") + + return prov +} diff --git a/sdk/.gitignore b/sdk/.gitignore new file mode 100644 index 0000000..c7f1555 --- /dev/null +++ b/sdk/.gitignore @@ -0,0 +1,3 @@ +/nodejs/bin/ +/nodejs/node_modules/ +/python/bin/ diff --git a/sdk/go.mod b/sdk/go.mod new file mode 100644 index 0000000..f120490 --- /dev/null +++ b/sdk/go.mod @@ -0,0 +1,5 @@ +module github.com/pulumi/pulumi-xyz/sdk + +go 1.17 + +require github.com/pulumi/pulumi/sdk/v3 v3.38.0