Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Required environment variables for running acceptance tests
CTRLPLANE_PROVIDER_TESTING_API_KEY=your_api_key_here
CTRLPLANE_PROVIDER_TESTING_WORKSPACE=your_workspace_here
CTRLPLANE_PROVIDER_TESTING_BASE_URL=https://app.ctrlplane.dev

# Test configuration
TF_ACC=1 # Required for running acceptance tests
TF_LOG=DEBUG # Optional: Set to DEBUG for verbose logging during tests
TF_LOG_PATH=./terraform.log # Optional: Log file path for test output

# Go test configuration
GO_TEST_TIMEOUT=120m # Test timeout duration
GO_TEST_PARALLEL=4 # Number of parallel tests to run

# Optional test configuration
TF_ACC=1 # Set to 1 to run acceptance tests
TF_LOG=INFO # Set to DEBUG for verbose logging during tests
23 changes: 7 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ name: Tests
on:
pull_request:
paths-ignore:
- 'README.md'
- "README.md"
push:
paths-ignore:
- 'README.md'
- "README.md"

# Testing only needs permissions to read the repository contents.
permissions:
Expand All @@ -25,7 +25,7 @@ jobs:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: 'go.mod'
go-version-file: "go.mod"
cache: true
- run: go mod download
- run: go build -v .
Expand All @@ -40,7 +40,7 @@ jobs:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: 'go.mod'
go-version-file: "go.mod"
cache: true
# We need the latest version of Terraform for our documentation generation to use
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
Expand All @@ -63,22 +63,13 @@ jobs:
matrix:
# list whatever Terraform versions here you would like to support
terraform:
- '1.0.*'
- '1.1.*'
- '1.2.*'
- '1.3.*'
- '1.4.*'
- '1.5.*'
- '1.6.*'
- '1.7.*'
- '1.8.*'
- '1.9.*'
- '1.10.*'
- "1.10.*"
- "1.11.*"
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: 'go.mod'
go-version-file: "go.mod"
cache: true
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
with:
Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@ website/vendor

# Keep windows files with windows line endings
*.winfile eol=crlf

.env
*.out
.cursor

# terraform
*.tfplan
*.tfstate
*.tfstate.backup
*.terraform.lock.hcl*
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ linters:
enable:
- durationcheck
- errcheck
- exportloopref
- forcetypeassert
- godot
- gofmt
Expand All @@ -18,9 +17,9 @@ linters:
- makezero
- misspell
- nilerr
- usetesting
- predeclared
- staticcheck
- tenv
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just deprecated now and I added one for tests.

- unconvert
- unparam
- unused
Expand Down
76 changes: 69 additions & 7 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,81 @@ lint:
generate:
cd tools; go generate ./...

generate-client:
cd client; go generate ./...

fmt:
gofmt -s -w -e .

update:
go get -u ./...

test:
go test -v -cover -timeout=120s -parallel=10 ./...
go test -v -cover -timeout=120s -parallel=10 ./... -skip TestIntegration TestAcc

testacc:
TF_ACC=1 go test -v -cover -timeout 120m ./...
@if [ ! -f .env ]; then \
echo "Error: .env file not found. Copy .env.example to .env and configure it."; \
exit 1; \
fi
@echo "Running acceptance tests..."
source .env && \
TF_ACC=1 \
CTRLPLANE_TOKEN="$${CTRLPLANE_PROVIDER_TESTING_API_KEY}" \
CTRLPLANE_WORKSPACE="$${CTRLPLANE_PROVIDER_TESTING_WORKSPACE}" \
CTRLPLANE_BASE_URL="$${CTRLPLANE_PROVIDER_TESTING_BASE_URL}" \
go test \
-timeout=$${GO_TEST_TIMEOUT:-120m} \
-parallel=$${GO_TEST_PARALLEL:-4} \
-cover \
$${TEST:-./internal/provider/...} $${TESTARGS}

test-acceptance:
testacc-quiet:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful for local testing because the tests are quite noisy.

@if [ ! -f .env ]; then \
echo "Error: .env file not found. Copy .env.example to .env and configure it."; \
exit 1; \
fi
@echo "Running acceptance tests with reduced verbosity..."
source .env && \
TF_ACC=1 \
CTRLPLANE_TOKEN=$(CTRLPLANE_PROVIDER_TESTING_API_KEY) \
CTRLPLANE_WORKSPACE=$(CTRLPLANE_PROVIDER_TESTING_WORKSPACE) \
go test -v -cover -timeout 120m ./...
TF_LOG=ERROR \
CTRLPLANE_TOKEN="$${CTRLPLANE_PROVIDER_TESTING_API_KEY}" \
CTRLPLANE_WORKSPACE="$${CTRLPLANE_PROVIDER_TESTING_WORKSPACE}" \
CTRLPLANE_BASE_URL="$${CTRLPLANE_PROVIDER_TESTING_BASE_URL}" \
go test \
-timeout=$${GO_TEST_TIMEOUT:-120m} \
-parallel=$${GO_TEST_PARALLEL:-4} \
-cover \
-v=0 \
$${TEST:-./internal/provider/...} $${TESTARGS}

testint:
@if [ ! -f .env ]; then \
echo "Error: .env file not found. Copy .env.example to .env and configure it."; \
exit 1; \
fi
@echo "Running integration tests..."
source .env && \
INTEGRATION_TEST_MODE="$${INTEGRATION_TEST_MODE:-autocleanup}" \
CTRLPLANE_TOKEN="$${CTRLPLANE_PROVIDER_TESTING_API_KEY}" \
CTRLPLANE_WORKSPACE="$${CTRLPLANE_PROVIDER_TESTING_WORKSPACE}" \
CTRLPLANE_BASE_URL="$${CTRLPLANE_PROVIDER_TESTING_BASE_URL}" \
go run github.com/onsi/ginkgo/v2/ginkgo run -v ./internal/integration

testexamples: build
for dir in examples/resources/*; do \
cd $$dir && \
terraform init && \
terraform plan -out=plan.tfplan && \
terraform apply plan.tfplan -auto-approve; \
terraform destroy -auto-approve; \
done

# Clean test artifacts
clean:
rm -f terraform.log
rm -rf .terraform
rm -f .terraform.lock.hcl
rm -f terraform.tfstate*

.PHONY: fmt lint test testacc build install generate
.PHONY: fmt lint test testacc testint testexamples build install generate clean install-local
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

_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._

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:
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:

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

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

*Note:* Acceptance tests create real resources, and often cost money to run.
_Note:_ Acceptance tests create real resources, and often cost money to run.

Create a `.env` file with the following environment variables:

```shell
CTRLPLANE_PROVIDER_TESTING_BASE_URL=http://localhost:3000
CTRLPLANE_PROVIDER_TESTING_API_KEY=your_token_here
CTRLPLANE_PROVIDER_TESTING_WORKSPACE=your_workspace_here
```

```shell
make testacc
Expand Down
Loading