generated from hashicorp/terraform-provider-scaffolding-framework
-
-
Notifications
You must be signed in to change notification settings - Fork 1
130 lines (123 loc) · 4.25 KB
/
test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# 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 }}