Merge pull request #203 from gonzolino/dependabot/github_actions/gore… #511
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Terraform Provider testing workflow. | |
name: Tests | |
# This GitHub action runs your tests for each pull request and push. | |
# Optionally, you can turn it on using a schedule for regular testing. | |
on: | |
pull_request: | |
paths-ignore: | |
- "README.md" | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- "README.md" | |
# Testing only needs permissions to read the repository contents. | |
permissions: | |
contents: read | |
# Default values to simplify job configurations below. | |
env: | |
# Go language version to use for building. This value should also be updated | |
# in the release workflow if changed. | |
GO_VERSION: "1.21" | |
jobs: | |
# Ensure project builds before running testing matrix | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
steps: | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- uses: actions/checkout@v4 | |
- run: go mod download | |
- run: go build -v . | |
setup_test_env: | |
name: Setup Acceptance Test Environment | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
outputs: | |
pdsn_server_url: ${{ steps.server_address.outputs.url }} | |
server_name: ${{ steps.random.outputs.server_name }} | |
steps: | |
- uses: actions/checkout@v4 | |
- id: random | |
run: | | |
random_mysql_root_password=$(uuidgen) | |
echo "::add-mask::$random_mysql_root_password" | |
echo "mysql_root_password=$random_mysql_root_password" >> $GITHUB_OUTPUT | |
random_pdns_webserver_password=$(uuidgen) | |
echo "::add-mask::$random_pdns_webserver_password" | |
echo "pdns_webserver_password=$random_pdns_webserver_password" >> $GITHUB_OUTPUT | |
echo "server_name=tf-pdns-$(uuidgen)" >> $GITHUB_OUTPUT | |
- uses: chuhlomin/render-template@v1.10 | |
with: | |
template: files/cloud-config.yaml | |
vars: | | |
mysql_root_password: ${{ steps.random.outputs.mysql_root_password }} | |
pdns_api_key: ${{ secrets.POWERDNS_API_KEY }} | |
pdns_webserver_password: ${{ steps.random.outputs.pdns_webserver_password }} | |
result_path: cloud-config.yaml | |
- uses: 3bit/setup-hcloud@v2 | |
- run: | | |
hcloud server create --name ${{ steps.random.outputs.server_name }} \ | |
--type cx22 \ | |
--image docker-ce \ | |
--ssh-key terraform-provider-powerdns \ | |
--location nbg1 \ | |
--user-data-from-file cloud-config.yaml | |
env: | |
HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }} | |
- id: server_address | |
run: echo "url=http://$(hcloud server ip ${{ steps.random.outputs.server_name }}):8081/api/v1" >> $GITHUB_OUTPUT | |
env: | |
HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }} | |
# Give the test server some time to start its services | |
- run: sleep 60 | |
- run: 'curl -H "X-API-Key: ${{ secrets.POWERDNS_API_KEY }}" -d @files/example-zone.json ${{ steps.server_address.outputs.url }}/servers/localhost/zones' | |
# Run acceptance tests in a matrix with Terraform CLI versions | |
test: | |
name: Terraform Provider Acceptance Tests | |
needs: | |
- build | |
- setup_test_env | |
runs-on: ubuntu-latest | |
timeout-minutes: 15 | |
strategy: | |
fail-fast: false | |
matrix: | |
# list whatever Terraform versions here you would like to support | |
terraform: | |
- "1.6.*" | |
- "1.7.*" | |
- "1.8.*" | |
- "1.9.*" | |
steps: | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: ${{ matrix.terraform }} | |
terraform_wrapper: false | |
- uses: actions/checkout@v4 | |
- run: go mod download | |
- env: | |
TF_ACC: "1" | |
POWERDNS_API_KEY: ${{ secrets.POWERDNS_API_KEY }} | |
POWERDNS_SERVER_URL: ${{ needs.setup_test_env.outputs.pdsn_server_url }} | |
run: go test -v -cover ./internal/provider/ | |
timeout-minutes: 10 | |
teardown_test_env: | |
name: Teardown Acceptance Test Environment | |
runs-on: ubuntu-latest | |
needs: | |
- setup_test_env | |
- test | |
if: ${{ always() }} | |
steps: | |
- uses: 3bit/setup-hcloud@v2 | |
- run: | | |
hcloud server delete ${{ needs.setup_test_env.outputs.server_name }} | |
env: | |
HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }} |