Skip to content

Commit 7c8b6b5

Browse files
Merge pull request #7 from ctrlplanedev/zacharyb/environments
feat: Environments
2 parents ce7842d + fda5dc4 commit 7c8b6b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+7470
-872
lines changed

.env.example

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Required environment variables for running acceptance tests
2+
CTRLPLANE_PROVIDER_TESTING_API_KEY=your_api_key_here
3+
CTRLPLANE_PROVIDER_TESTING_WORKSPACE=your_workspace_here
4+
CTRLPLANE_PROVIDER_TESTING_BASE_URL=https://app.ctrlplane.dev
5+
6+
# Test configuration
7+
TF_ACC=1 # Required for running acceptance tests
8+
TF_LOG=DEBUG # Optional: Set to DEBUG for verbose logging during tests
9+
TF_LOG_PATH=./terraform.log # Optional: Log file path for test output
10+
11+
# Go test configuration
12+
GO_TEST_TIMEOUT=120m # Test timeout duration
13+
GO_TEST_PARALLEL=4 # Number of parallel tests to run
14+
15+
# Optional test configuration
16+
TF_ACC=1 # Set to 1 to run acceptance tests
17+
TF_LOG=INFO # Set to DEBUG for verbose logging during tests

.github/workflows/test.yml

+7-16
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ name: Tests
66
on:
77
pull_request:
88
paths-ignore:
9-
- 'README.md'
9+
- "README.md"
1010
push:
1111
paths-ignore:
12-
- 'README.md'
12+
- "README.md"
1313

1414
# Testing only needs permissions to read the repository contents.
1515
permissions:
@@ -25,7 +25,7 @@ jobs:
2525
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
2626
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
2727
with:
28-
go-version-file: 'go.mod'
28+
go-version-file: "go.mod"
2929
cache: true
3030
- run: go mod download
3131
- run: go build -v .
@@ -40,7 +40,7 @@ jobs:
4040
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
4141
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
4242
with:
43-
go-version-file: 'go.mod'
43+
go-version-file: "go.mod"
4444
cache: true
4545
# We need the latest version of Terraform for our documentation generation to use
4646
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
@@ -63,22 +63,13 @@ jobs:
6363
matrix:
6464
# list whatever Terraform versions here you would like to support
6565
terraform:
66-
- '1.0.*'
67-
- '1.1.*'
68-
- '1.2.*'
69-
- '1.3.*'
70-
- '1.4.*'
71-
- '1.5.*'
72-
- '1.6.*'
73-
- '1.7.*'
74-
- '1.8.*'
75-
- '1.9.*'
76-
- '1.10.*'
66+
- "1.10.*"
67+
- "1.11.*"
7768
steps:
7869
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
7970
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
8071
with:
81-
go-version-file: 'go.mod'
72+
go-version-file: "go.mod"
8273
cache: true
8374
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
8475
with:

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,13 @@ website/vendor
3333

3434
# Keep windows files with windows line endings
3535
*.winfile eol=crlf
36+
37+
.env
38+
*.out
39+
.cursor
40+
41+
# terraform
42+
*.tfplan
43+
*.tfstate
44+
*.tfstate.backup
45+
*.terraform.lock.hcl*

.golangci.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ linters:
99
enable:
1010
- durationcheck
1111
- errcheck
12-
- exportloopref
1312
- forcetypeassert
1413
- godot
1514
- gofmt
@@ -18,9 +17,9 @@ linters:
1817
- makezero
1918
- misspell
2019
- nilerr
20+
- usetesting
2121
- predeclared
2222
- staticcheck
23-
- tenv
2423
- unconvert
2524
- unparam
2625
- unused

GNUmakefile

+69-7
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,81 @@ lint:
1212
generate:
1313
cd tools; go generate ./...
1414

15+
generate-client:
16+
cd client; go generate ./...
17+
1518
fmt:
1619
gofmt -s -w -e .
1720

21+
update:
22+
go get -u ./...
23+
1824
test:
19-
go test -v -cover -timeout=120s -parallel=10 ./...
25+
go test -v -cover -timeout=120s -parallel=10 ./... -skip TestIntegration TestAcc
2026

2127
testacc:
22-
TF_ACC=1 go test -v -cover -timeout 120m ./...
28+
@if [ ! -f .env ]; then \
29+
echo "Error: .env file not found. Copy .env.example to .env and configure it."; \
30+
exit 1; \
31+
fi
32+
@echo "Running acceptance tests..."
33+
source .env && \
34+
TF_ACC=1 \
35+
CTRLPLANE_TOKEN="$${CTRLPLANE_PROVIDER_TESTING_API_KEY}" \
36+
CTRLPLANE_WORKSPACE="$${CTRLPLANE_PROVIDER_TESTING_WORKSPACE}" \
37+
CTRLPLANE_BASE_URL="$${CTRLPLANE_PROVIDER_TESTING_BASE_URL}" \
38+
go test \
39+
-timeout=$${GO_TEST_TIMEOUT:-120m} \
40+
-parallel=$${GO_TEST_PARALLEL:-4} \
41+
-cover \
42+
$${TEST:-./internal/provider/...} $${TESTARGS}
2343

24-
test-acceptance:
44+
testacc-quiet:
45+
@if [ ! -f .env ]; then \
46+
echo "Error: .env file not found. Copy .env.example to .env and configure it."; \
47+
exit 1; \
48+
fi
49+
@echo "Running acceptance tests with reduced verbosity..."
50+
source .env && \
2551
TF_ACC=1 \
26-
CTRLPLANE_TOKEN=$(CTRLPLANE_PROVIDER_TESTING_API_KEY) \
27-
CTRLPLANE_WORKSPACE=$(CTRLPLANE_PROVIDER_TESTING_WORKSPACE) \
28-
go test -v -cover -timeout 120m ./...
52+
TF_LOG=ERROR \
53+
CTRLPLANE_TOKEN="$${CTRLPLANE_PROVIDER_TESTING_API_KEY}" \
54+
CTRLPLANE_WORKSPACE="$${CTRLPLANE_PROVIDER_TESTING_WORKSPACE}" \
55+
CTRLPLANE_BASE_URL="$${CTRLPLANE_PROVIDER_TESTING_BASE_URL}" \
56+
go test \
57+
-timeout=$${GO_TEST_TIMEOUT:-120m} \
58+
-parallel=$${GO_TEST_PARALLEL:-4} \
59+
-cover \
60+
-v=0 \
61+
$${TEST:-./internal/provider/...} $${TESTARGS}
62+
63+
testint:
64+
@if [ ! -f .env ]; then \
65+
echo "Error: .env file not found. Copy .env.example to .env and configure it."; \
66+
exit 1; \
67+
fi
68+
@echo "Running integration tests..."
69+
source .env && \
70+
INTEGRATION_TEST_MODE="$${INTEGRATION_TEST_MODE:-autocleanup}" \
71+
CTRLPLANE_TOKEN="$${CTRLPLANE_PROVIDER_TESTING_API_KEY}" \
72+
CTRLPLANE_WORKSPACE="$${CTRLPLANE_PROVIDER_TESTING_WORKSPACE}" \
73+
CTRLPLANE_BASE_URL="$${CTRLPLANE_PROVIDER_TESTING_BASE_URL}" \
74+
go run github.com/onsi/ginkgo/v2/ginkgo run -v ./internal/integration
75+
76+
testexamples: build
77+
for dir in examples/resources/*; do \
78+
cd $$dir && \
79+
terraform init && \
80+
terraform plan -out=plan.tfplan && \
81+
terraform apply plan.tfplan -auto-approve; \
82+
terraform destroy -auto-approve; \
83+
done
84+
85+
# Clean test artifacts
86+
clean:
87+
rm -f terraform.log
88+
rm -rf .terraform
89+
rm -f .terraform.lock.hcl
90+
rm -f terraform.tfstate*
2991

30-
.PHONY: fmt lint test testacc build install generate
92+
.PHONY: fmt lint test testacc testint testexamples build install generate clean install-local

README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
_This template repository is built on the [Terraform Plugin Framework](https://github.com/hashicorp/terraform-plugin-framework). The template repository built on the [Terraform Plugin SDK](https://github.com/hashicorp/terraform-plugin-sdk) can be found at [terraform-provider-scaffolding](https://github.com/hashicorp/terraform-provider-scaffolding). See [Which SDK Should I Use?](https://developer.hashicorp.com/terraform/plugin/framework-benefits) in the Terraform documentation for additional information._
44

5-
This repository is a *template* for a [Terraform](https://www.terraform.io) provider. It is intended as a starting point for creating Terraform providers, containing:
5+
This repository is a _template_ for a [Terraform](https://www.terraform.io) provider. It is intended as a starting point for creating Terraform providers, containing:
66

77
- A resource and a data source (`internal/provider/`),
88
- Examples (`examples/`) and generated documentation (`docs/`),
@@ -57,7 +57,15 @@ To generate or update documentation, run `make generate`.
5757

5858
In order to run the full suite of Acceptance tests, run `make testacc`.
5959

60-
*Note:* Acceptance tests create real resources, and often cost money to run.
60+
_Note:_ Acceptance tests create real resources, and often cost money to run.
61+
62+
Create a `.env` file with the following environment variables:
63+
64+
```shell
65+
CTRLPLANE_PROVIDER_TESTING_BASE_URL=http://localhost:3000
66+
CTRLPLANE_PROVIDER_TESTING_API_KEY=your_token_here
67+
CTRLPLANE_PROVIDER_TESTING_WORKSPACE=your_workspace_here
68+
```
6169

6270
```shell
6371
make testacc

0 commit comments

Comments
 (0)