Skip to content

Commit e00330e

Browse files
authored
ref: Only run the latest version of Terraform on PRs (#542)
* ref: Only run the latest version of Terraform on PRs * fix: lint errors
1 parent 51b3d78 commit e00330e

File tree

8 files changed

+128
-68
lines changed

8 files changed

+128
-68
lines changed

.github/workflows/test.yml

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# This GitHub action runs your tests for each commit push and/or PR. Optionally
2-
# you can turn it on using a cron schedule for regular testing.
3-
#
1+
# Terraform Provider testing workflow.
42
name: Tests
3+
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.
56
on:
67
pull_request:
78
branches:
@@ -17,48 +18,58 @@ on:
1718
# to an API change, even if the code did not change.
1819
schedule:
1920
- cron: "0 0 * * *"
21+
22+
# Testing only needs permissions to read the repository contents.
23+
permissions:
24+
contents: read
25+
2026
concurrency:
2127
group: ${{ github.workflow }}-${{ github.ref }}
2228
cancel-in-progress: true
29+
2330
jobs:
24-
# ensure the code builds...
31+
# Ensure project builds before running testing matrix
2532
build:
2633
name: Build
2734
runs-on: ubuntu-latest
2835
timeout-minutes: 5
2936
steps:
30-
- uses: actions/checkout@v4
31-
- uses: actions/setup-go@v5
37+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
38+
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
3239
with:
3340
go-version-file: "go.mod"
3441
cache: true
35-
- name: Get dependencies
36-
run: |
37-
go mod download
38-
- name: Build
39-
run: |
40-
go build -v .
42+
- run: go mod download
43+
- run: go build -v .
44+
- name: Run linters
45+
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1
46+
with:
47+
version: latest
4148

4249
generate:
4350
runs-on: ubuntu-latest
4451
steps:
45-
- uses: actions/checkout@v4
46-
- uses: actions/setup-go@v5
52+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
53+
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
4754
with:
4855
go-version-file: "go.mod"
4956
cache: true
50-
- run: go generate ./...
57+
# We need the latest version of Terraform for our documentation generation to use
58+
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
59+
with:
60+
terraform_wrapper: false
61+
- run: make generate
5162
- name: git diff
5263
run: |
53-
git diff --exit-code || \
54-
(echo; echo "Unexpected difference in directories after code generation. Run 'go generate ./...' command and commit."; exit 1)
64+
git diff --compact-summary --exit-code || \
65+
(echo; echo "Unexpected difference in directories after code generation. Run 'make generate' command and commit."; exit 1)
5566
56-
# run acceptance tests in a matrix with Terraform core versions
67+
# Run acceptance tests in a matrix with Terraform CLI versions
5768
test:
58-
name: Matrix Test
69+
name: Terraform Provider Acceptance Tests
5970
needs: build
6071
runs-on: ubuntu-latest
61-
timeout-minutes: 30
72+
timeout-minutes: 15
6273
strategy:
6374
fail-fast: false
6475
max-parallel: 1
@@ -69,25 +80,36 @@ jobs:
6980
- "1.6.*"
7081
- "1.7.*"
7182
- "1.8.*"
83+
- "1.9.*"
84+
- "1.10.*"
85+
is-pr:
86+
- ${{ github.event_name == 'pull_request' }}
87+
# Only run the latest version of Terraform on pull requests
88+
exclude:
89+
- terraform: "1.4.*"
90+
is-pr: true
91+
- terraform: "1.5.*"
92+
is-pr: true
93+
- terraform: "1.6.*"
94+
is-pr: true
95+
- terraform: "1.7.*"
96+
is-pr: true
97+
- terraform: "1.8.*"
98+
is-pr: true
99+
- terraform: "1.9.*"
100+
is-pr: true
72101
steps:
73-
- uses: actions/checkout@v4
74-
- uses: actions/setup-go@v5
102+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
103+
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
75104
with:
76105
go-version-file: "go.mod"
77106
cache: true
78-
79-
- uses: hashicorp/setup-terraform@v3
107+
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
80108
with:
81109
terraform_version: ${{ matrix.terraform }}
82110
terraform_wrapper: false
83-
84-
- name: Get dependencies
85-
run: |
86-
go mod download
87-
88-
- name: TF acceptance tests
89-
timeout-minutes: 30
90-
env:
111+
- run: go mod download
112+
- env:
91113
TF_ACC: "1"
92114
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
93115
SENTRY_TEST_GITHUB_INSTALLATION_ID: ${{ secrets.SENTRY_TEST_GITHUB_INSTALLATION_ID }}
@@ -100,5 +122,5 @@ jobs:
100122
SENTRY_TEST_PAGERDUTY_ORGANIZATION: ${{ secrets.SENTRY_TEST_PAGERDUTY_ORGANIZATION }}
101123
SENTRY_TEST_VSTS_INSTALLATION_ID: ${{ secrets.SENTRY_TEST_VSTS_INSTALLATION_ID }}
102124
SENTRY_TEST_VSTS_REPOSITORY_IDENTIFIER: ${{ secrets.SENTRY_TEST_VSTS_REPOSITORY_IDENTIFIER }}
103-
run: |
104-
go test -v -cover -timeout 30m ./...
125+
run: go test -v -cover ./internal/provider/
126+
timeout-minutes: 10

GNUmakefile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
SWEEP ?= cloud
2+
SWEEP_TIMEOUT ?= 360m
3+
4+
default: fmt lint install generate
5+
6+
.PHONY: build
7+
build:
8+
go build -v ./...
9+
10+
.PHONY: install
11+
install: build
12+
go install -v ./...
13+
14+
.PHONY: lint
15+
lint:
16+
golangci-lint run
17+
18+
.PHONY: generate
19+
generate:
20+
go generate ./...
21+
22+
.PHONY: fmt
23+
fmt:
24+
gofmt -s -w -e .
25+
26+
.PHONY: test
27+
test:
28+
go test -v -cover -timeout=120s -parallel=10 ./...
29+
30+
.PHONY: testacc
31+
testacc:
32+
TF_ACC=1 go test -v -cover -timeout 120m ./...
33+
34+
.PHONY: sweep
35+
sweep:
36+
# make sweep SWEEPARGS=-sweep-run=sentry_team
37+
# set SWEEPARGS=-sweep-allow-failures to continue after first failure
38+
@echo "WARNING: This will destroy infrastructure. Use only in development accounts."
39+
go test ./... -v -sweep=$(SWEEP) $(SWEEPARGS) -timeout $(SWEEP_TIMEOUT)
40+
41+
.PHONY: sweeper
42+
sweeper:
43+
@echo "WARNING: This will destroy infrastructure. Use only in development accounts."
44+
go test ./... -v -tags=sweep -sweep=$(SWEEP) -sweep-allow-failures -timeout $(SWEEP_TIMEOUT)

Makefile

Lines changed: 0 additions & 24 deletions
This file was deleted.

internal/provider/resource_organization_repository_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func TestAccOrganizationRepositoryResource_GitHub(t *testing.T) {
9898
t.Skip("Skipping test due to missing SENTRY_TEST_GITHUB_REPOSITORY_IDENTIFIER environment variable")
9999
}
100100

101-
testAccOrganizationRepositoryResourcePreCheck()
101+
must.Do(testAccOrganizationRepositoryResourcePreCheck())
102102
},
103103
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
104104
Steps: []resource.TestStep{
@@ -150,7 +150,7 @@ func TestAccOrganizationRepositoryResource_GitLab(t *testing.T) {
150150
t.Skip("Skipping test due to missing SENTRY_TEST_GITLAB_REPOSITORY_IDENTIFIER environment variable")
151151
}
152152

153-
testAccOrganizationRepositoryResourcePreCheck()
153+
must.Do(testAccOrganizationRepositoryResourcePreCheck())
154154
},
155155
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
156156
Steps: []resource.TestStep{
@@ -202,7 +202,7 @@ func TestAccOrganizationRepositoryResource_VSTS(t *testing.T) {
202202
t.Skip("Skipping test due to missing SENTRY_TEST_VSTS_REPOSITORY_IDENTIFIER environment variable")
203203
}
204204

205-
testAccOrganizationRepositoryResourcePreCheck()
205+
must.Do(testAccOrganizationRepositoryResourcePreCheck())
206206
},
207207
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
208208
Steps: []resource.TestStep{

internal/provider/resource_project.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ func (m *ProjectResourceModel) Fill(project apiclient.Project) error {
124124
m.ResolveAge = types.Int64Value(project.ResolveAge)
125125

126126
if m.Filters != nil {
127-
m.Filters.Fill(project)
127+
if err := m.Filters.Fill(project); err != nil {
128+
return err
129+
}
128130
}
129131

130132
m.FingerprintingRules = sentrytypes.TrimmedStringValue(project.FingerprintingRules)

sentry/resource_sentry_organization_code_mappings.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ func resourceSentryOrganizationCodeMappingCreate(ctx context.Context, d *schema.
9393
}
9494

9595
d.SetId(orgCodeMapping.ID)
96-
d.Set("internal_id", orgCodeMapping.ID)
96+
if err := d.Set("internal_id", orgCodeMapping.ID); err != nil {
97+
return diag.FromErr(err)
98+
}
9799
return resourceSentryOrganizationCodeMappingRead(ctx, d, meta)
98100
}
99101

@@ -178,7 +180,9 @@ func resourceSentryOrganizationCodeMappingUpdate(ctx context.Context, d *schema.
178180
}
179181

180182
d.SetId(orgCodeMapping.ID)
181-
d.Set("internal_id", orgCodeMapping.ID)
183+
if err := d.Set("internal_id", orgCodeMapping.ID); err != nil {
184+
return diag.FromErr(err)
185+
}
182186

183187
return resourceSentryOrganizationCodeMappingRead(ctx, d, meta)
184188
}
@@ -204,7 +208,9 @@ func importSentryOrganizationCodeMapping(ctx context.Context, d *schema.Resource
204208
}
205209

206210
d.SetId(id)
207-
d.Set("organization", org)
211+
if err := d.Set("organization", org); err != nil {
212+
return nil, err
213+
}
208214

209215
resourceSentryOrganizationCodeMappingRead(ctx, d, meta)
210216

sentry/resource_sentry_organization_member.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ func resourceSentryOrganizationMemberRead(ctx context.Context, d *schema.Resourc
9696
client := meta.(*providerdata.ProviderData).Client
9797

9898
org, memberID, err := splitSentryOrganizationMemberID(d.Id())
99+
if err != nil {
100+
return diag.FromErr(err)
101+
}
99102

100103
tflog.Debug(ctx, "Reading organization member", map[string]interface{}{
101104
"org": org,

sentry/resource_sentry_organization_repository_github.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ func resourceSentryOrganizationRepositoryGithubCreate(ctx context.Context, d *sc
8686
// You can connect multiple GitHub organizations to one Sentry organization, but you cannot connect a single GitHub organization to multiple Sentry organizations.
8787
// https://docs.sentry.io/product/integrations/source-code-mgmt/github/
8888
d.SetId(identifier)
89-
d.Set("internal_id", orgRepo.ID)
89+
if err := d.Set("internal_id", orgRepo.ID); err != nil {
90+
return diag.FromErr(err)
91+
}
9092

9193
return resourceSentryOrganizationRepositoryGithubRead(ctx, d, meta)
9294
}
@@ -172,8 +174,13 @@ func importSentryOrganizationRepositoryGithub(ctx context.Context, d *schema.Res
172174
}
173175

174176
d.SetId(id)
175-
d.Set("identifier", id)
176-
d.Set("organization", org)
177+
if err := d.Set("identifier", id); err != nil {
178+
return nil, err
179+
}
180+
181+
if err := d.Set("organization", org); err != nil {
182+
return nil, err
183+
}
177184

178185
resourceSentryOrganizationRepositoryGithubRead(ctx, d, meta)
179186

0 commit comments

Comments
 (0)