Skip to content

Commit 5078b10

Browse files
Terraform Support 1.12.x (#91)
* Moved pipeline authentication bootstrapping from shell scripts to go, using client-go SDK. * Added missing https protocol to HOST env var. * Fixed error in copying PROJECT_NAME to env var within bootstrap_pipeline.go. * Fixed to use existing password when attempting to update password within bootstrap_pipeline.go. Removed NEW_PASSWORD env var, as it is now unused due to replacing use with PASSWORD. * Specified type BOOLEAN for parameter for disabling NVD mirroring. * Moved TF acceptance testing to a composite action. * Moved actions/action-test.yml to actions/test/action.yml in line with docs. * Specified shell as bash within actions/test composite action. * Split test into 2 sub steps, based on whether using client certs. Added 1.12.* to list of Terraform versions tested against. * Added env value to disable telemtry that was accidentally removed when trimming down comments in workflow. * Update README, and CHANGELOG.
1 parent 04a8d69 commit 5078b10

File tree

7 files changed

+276
-72
lines changed

7 files changed

+276
-72
lines changed

.github/actions/test/action.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: "Parametrised Terraform Acceptance Test"
2+
description: "Relies on existing service containers for DependencyTrack API, and actions/checkout having run"
3+
4+
inputs:
5+
terraform_version:
6+
description: "Version of Terraform to be used to run tests."
7+
required: true
8+
provider_config_key:
9+
description: "Config key to determine which provider config to use, as defined within provider_test.go."
10+
required: true
11+
12+
runs:
13+
using: "composite"
14+
steps:
15+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
16+
with:
17+
go-version-file: 'go.mod'
18+
cache: true
19+
- name: Bootstrap authentication
20+
shell: bash
21+
run: |
22+
set -eu
23+
export API_KEY="$(go run ./scripts/bootstrap_pipeline.go)"
24+
echo "DEPENDENCYTRACK_API_KEY=${API_KEY}" >> $GITHUB_ENV
25+
env:
26+
HOST: "http://localhost:8081"
27+
USERNAME: "admin"
28+
CURRENT_PASSWORD: "admin"
29+
PASSWORD: "pipeline"
30+
TEAM_NAME: "Pipeline ${{ inputs.terraform }}"
31+
PROJECT_NAME: "Project_Data_Test"
32+
PROJECT_VERSION: "1"
33+
34+
- name: Setup Nginx
35+
shell: bash
36+
run: |
37+
set -eu
38+
openssl req -newkey rsa:4096 -noenc -keyout /opt/server_key.pem -x509 -days 1 -out /opt/server_cert.pem -subj '/OU=DT_API /CN=localhost' -addext "subjectAltName=DNS:localhost"
39+
openssl req -newkey rsa:4096 -noenc -keyout /opt/client_key.pem -x509 -days 1 -out /opt/client_cert.pem -subj '/OU=DT_Provider'
40+
sudo apt-get install nginx
41+
sudo mkdir -p /etc/nginx
42+
sudo cp nginx.conf /etc/nginx/
43+
sudo nginx
44+
45+
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
46+
with:
47+
terraform_version: ${{ inputs.terraform }}
48+
terraform_wrapper: false
49+
- run: go mod download
50+
shell: bash
51+
- run: go test -v -cover ./internal/provider/
52+
shell: bash
53+
env:
54+
TF_ACC: "1"
55+
DEPENDENCYTRACK_TEST_PROVIDER: ${{ inputs.provider_config_key }}
56+
#TF_LOG: "info"

.github/workflows/test.yml

Lines changed: 47 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
# Terraform Provider testing workflow.
21
name: Tests
32

4-
# This GitHub action runs your tests for each pull request and push.
5-
# Optionally, you can turn it on using a schedule for regular testing.
63
on:
74
pull_request:
85
paths-ignore:
@@ -89,31 +86,15 @@ jobs:
8986
fail-fast: false
9087
matrix:
9188
api:
92-
# TODO: Adjust logic according to versions to allow supporting older API versions.
93-
# - "4.0.1"
94-
# - "4.1.0"
95-
# - "4.2.2"
96-
# - "4.3.6"
97-
# - "4.4.2"
98-
# - "4.5.0"
99-
# - "4.6.3"
100-
# - "4.7.1"
101-
# - "4.8.2"
102-
# - "4.9.1"
103-
# - "4.10.1"
89+
# TODO: Adjust logic according to versions to allow supporting older API versions, as required.
10490
- "4.11.7"
10591
- "4.12.7"
10692
- "4.13.0"
10793
- "4.13.1"
10894
- "4.13.2"
109-
# - "latest"
110-
# - "snapshot"
11195
provider:
11296
- "default"
11397
- "rootCA"
114-
- "mtls"
115-
- "rootCA+mtls"
116-
# list whatever Terraform versions here you would like to support
11798
terraform:
11899
- '1.0.*'
119100
- '1.1.*'
@@ -127,59 +108,55 @@ jobs:
127108
- '1.9.*'
128109
- '1.10.*'
129110
- '1.11.*'
111+
- '1.12.*'
130112
steps:
131113
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
132-
- name: Bootstrap authentication
133-
shell: bash
134-
run: |
135-
set -euo pipefail
136-
./scripts/change-password.sh
137-
export TOKEN="$(./scripts/login.sh)"
138-
./scripts/disable-settings.sh
139-
export TEAM_UUID="$(./scripts/create-team.sh | jq -r '.uuid')"
140-
PERMISSIONS="$(./scripts/get-valid-permissions.sh | jq -r '.[].name')"
141-
for perm in ${PERMISSIONS}; do
142-
PERMISSION="${perm}" ./scripts/assign-permission.sh
143-
done
144-
export PROJECT_UUID="$(./scripts/create-project.sh | jq -r '.uuid')"
145-
GROUP_NAME="Group1" PROPERTY_NAME="Name1" PROPERTY_VALUE="Value1" PROPERTY_TYPE="STRING" DESCRIPTION="Description1" ./scripts/create-project-property.sh
146-
GROUP_NAME="Group2" PROPERTY_NAME="Name2" PROPERTY_VALUE="2" PROPERTY_TYPE="INTEGER" DESCRIPTION="Description2" ./scripts/create-project-property.sh
147-
export API_KEY="$(./scripts/create-token.sh | jq -r '.key')"
148-
echo "DEPENDENCYTRACK_API_KEY=${API_KEY}" >> $GITHUB_ENV
114+
- uses: ./.github/actions/test
115+
with:
116+
terraform_version: ${{ matrix.terraform }}
117+
provider_config_key: ${{ matrix.provider }}
149118

119+
test_mtls:
120+
name: Terraform Provider Acceptance Tests
121+
needs: build
122+
runs-on: ubuntu-latest
123+
timeout-minutes: 15
124+
services:
125+
api:
126+
image: dependencytrack/apiserver:${{ matrix.api }}
150127
env:
151-
HOST: "localhost:8081"
152-
USERNAME: "admin"
153-
CURRENT_PASSWORD: "admin"
154-
NEW_PASSWORD: "pipeline"
155-
PASSWORD: "pipeline"
156-
TEAM_NAME: "Pipeline ${{ matrix.terraform }}"
157-
PROJECT_NAME: "Project_Data_Test"
158-
PROJECT_VERSION: "1"
159-
160-
- name: Setup Nginx
161-
shell: bash
162-
run: |
163-
set -eu
164-
openssl req -newkey rsa:4096 -noenc -keyout /opt/server_key.pem -x509 -days 1 -out /opt/server_cert.pem -subj '/OU=DT_API /CN=localhost' -addext "subjectAltName=DNS:localhost"
165-
openssl req -newkey rsa:4096 -noenc -keyout /opt/client_key.pem -x509 -days 1 -out /opt/client_cert.pem -subj '/OU=DT_Provider'
166-
sudo apt-get install nginx
167-
sudo mkdir -p /etc/nginx
168-
sudo cp nginx.conf /etc/nginx/
169-
sudo nginx
170-
171-
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
172-
with:
173-
go-version-file: 'go.mod'
174-
cache: true
175-
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
128+
TELEMETRY_SUBMISSION_ENABLED_DEFAULT: false
129+
ports:
130+
- 8081:8080
131+
strategy:
132+
fail-fast: false
133+
matrix:
134+
api:
135+
- "4.11.7"
136+
- "4.12.7"
137+
- "4.13.0"
138+
- "4.13.1"
139+
- "4.13.2"
140+
provider:
141+
- "mtls"
142+
- "rootCA+mtls"
143+
terraform:
144+
- '1.0.*'
145+
- '1.1.*'
146+
- '1.2.*'
147+
- '1.3.*'
148+
- '1.4.*'
149+
- '1.5.*'
150+
- '1.6.*'
151+
- '1.7.*'
152+
- '1.8.*'
153+
- '1.9.*'
154+
- '1.10.*'
155+
- '1.11.*'
156+
- '1.12.*'
157+
steps:
158+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
159+
- uses: ./.github/actions/test
176160
with:
177161
terraform_version: ${{ matrix.terraform }}
178-
terraform_wrapper: false
179-
- run: go mod download
180-
- env:
181-
TF_ACC: "1"
182-
DEPENDENCYTRACK_TEST_PROVIDER: ${{ matrix.provider }}
183-
#TF_LOG: "info"
184-
run: go test -v -cover ./internal/provider/
185-
timeout-minutes: 10
162+
provider_config_key: ${{ matrix.provider }}

.golangci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,13 @@ linters:
464464
warn-unused: true # Default false
465465
presets: [] # Default []
466466
rules:
467+
- path: scripts/bootstrap_pipeline.go
468+
linters:
469+
- err113
470+
- cyclop
471+
- gochecknoglobals
472+
- exhaustruct
473+
- forbidigo
467474
- path: internal/provider/
468475
linters:
469476
- wsl

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## 1.12.4
2+
3+
#### FEATURES
4+
- Add explicit support and testing for Terraform `1.12.x`.
5+
6+
#### MISC
7+
- Replaced pipeline bootstrapping shell scripts with `scripts/bootstrap_pipeline.go` to use `client-go` SDK.
8+
- Move Terraform Acceptance Test GitHub workflow out of `test.yml`, into a composite action.
9+
- Split TF Acceptance tests to bypass limit of 256 jobs per matrix.
10+
- Trimmed down commented out DependencyTrack API versions within workflow.
11+
12+
#### DEPENDENCIES
13+
- `github.com/hashicorp/terraform-plugin-testing` `1.13.0` -> `1.13.1`
14+
- `github.com/hashicorp/terraform-plugin-go` `0.27.0` -> `0.28.0`
15+
116
## 1.12.3
217

318
#### FEATURES

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ Other API versions may work, with a subset of functionality, but are not guarant
4848
The latest patch version within a minor release is supported, even if it might not be tested - PR's to update would always be welcome.
4949
The list of API Versions will grow as functionality adapts to allow tests to pass, which at present is only a small subset.
5050
The latest 2 patches within the latest minor version will be tested, and supported to allow for continued support while migrating.
51-
- Terraform: `1.0` -> `1.11`
51+
- Terraform: `1.0` -> `1.12`
5252
- DependencyTrack: `4.11.7`, `4.12.7`, `4.13.0`, `4.13.1`, `4.13.2`

internal/provider/http_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const (
1919
)
2020

2121
var (
22-
projectPropertyURLRegex *regexp.Regexp = regexp.MustCompile("^/api/v1/project/" + uuidRegex + "/property$")
22+
projectPropertyURLRegex = regexp.MustCompile("^/api/v1/project/" + uuidRegex + "/property$")
2323
)
2424

2525
type (

0 commit comments

Comments
 (0)