Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker Compose file for local testing #187

Merged
merged 4 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 48 additions & 4 deletions _about/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,24 @@ though in general, running `make install` will be sufficient in the course of de

## Testing

There are two `make` commands regarding automated tests:
There are a few options for running tests depending on the type.

### Unit tests

The following command will run any regular unit tests. These are typically for helper or utility logic, such as data flatteners or equality checks.

```shell
make test
```

will run any regular unit tests. These are typically for helper or utility logic, such as data flatteners or equality checks.
### Terraform acceptance tests

The following command will run [TF acceptance tests](https://developer.hashicorp.com/terraform/plugin/testing/acceptance-tests), by prefixing the test run with `TF_ACC=1`.

```shell
make testacc
```

will run [TF acceptance tests](https://developer.hashicorp.com/terraform/plugin/testing/acceptance-tests), by prefixing the test run with `TF_ACC=1`

**NOTE:** Acceptance tests create real Prefect Cloud resources, and require a Prefect Cloud account when running locally

**NOTE:** In most development/contribution cases, acceptance tests will be run in CI/CD via Github Actions, as test-specific credentials are stored in the environment there. However, if there are instances where a developer wishes to run the tests locally - they can initialize their test provider through the normal environment variables, pointed to an account that they own:
Expand All @@ -107,6 +111,46 @@ export PREFECT_CLOUD_ACCOUNT_ID=<uuid>
make testacc
```

### Integration tests

You can also test against a local instance of Prefect. An example of this setup using Docker Compose is available in the [Terraform Provider tutorial](https://developer.hashicorp.com/terraform/tutorials/providers-plugin-framework/providers-plugin-framework-provider).

First, you'll need to create or modify `~/.terraformrc` on your machine:

```terraform
provider_installation {
dev_overrides {
"registry.terraform.io/prefecthq/prefect" = "/Users/<username>/go/bin/"
}

# For all other providers, install them directly from their origin provider
# registries as normal. If you omit this, Terraform will _only_ use
# the dev_overrides block, and so no other providers will be available.
direct {}
}
```

You only need to do this once, but if you will need to comment this out any time you want to use the provider from the official Terraform registry instead.

Next, start the Prefect server:

```shell
docker-compose up -d
```

You can confirm the server is running by either:

1. Checking the logs with `docker-compose logs -f`, or
2. Navigating to the UI in your browser at [localhost:4200](http://localhost:4200).

When you're ready to test your changes, compile the provider and install it to your path:

```shell
go install .
```

You can now run `terraform plan` and `terraform apply` to test features in the provider.

## Build Documentation

This provider repository uses the [`tfplugindocs`](https://github.com/hashicorp/terraform-plugin-docs) CLI utility to generate markdown documentation.
Expand Down
19 changes: 19 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file is used to run a local instance of
mitchnielsen marked this conversation as resolved.
Show resolved Hide resolved
# Prefect for testing our Terraform Provider.
#
# See ./_about/CONTRIBUTING.md.
services:
prefect:
image: prefecthq/prefect:2-latest
mitchnielsen marked this conversation as resolved.
Show resolved Hide resolved
ports:
- "4200:4200"
environment:
PREFECT_LOGGING_LEVEL: debug
command:
- prefect
- server
- start
- --host
- "0.0.0.0"
- --port
- "4200"
18 changes: 18 additions & 0 deletions examples/provider-install-verification/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
terraform {
required_providers {
prefect = {
source = "registry.terraform.io/prefecthq/prefect"
}
}
}

provider "prefect" {
endpoint = "http://localhost:4200/api"
}

resource "prefect_work_pool" "example" {
name = "my-work-pool"
type = "kubernetes"
description = "example work pool"
paused = true
}