terraform-provider-imagetest

command module
v0.0.61 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2025 License: MPL-2.0 Imports: 10 Imported by: 0

README

Terraform Provider Image Test

🚨 This is a work in progress 🚨

A terraform provider for authoring and executing tests using terraform primitives. Designed to work in conjunction with the Chainguard Images project. I would strongly recommend against using it for anything else.

See examples for usages, and design for more information about the providers design.

Testing the provider

Basic acceptance tests:

IMAGETEST_ENTRYPOINT_REF=$(KO_DOCKER_REPO=ttl.sh/imagetest ko build ./cmd/entrypoint) \
    TF_ACC=1 \
    go test ./internal/provider/... -count=1 -v

This will build and use the entrypoint image, and use it in the test.

Testing the EKS driver takes a lot longer, and creates resources which might cost money. To run these tests, ensure you have AWS auth set up and eksctl installed, then run:

IMAGETEST_ENTRYPOINT_REF=$(KO_DOCKER_REPO=ttl.sh/imagetest ko build ./cmd/entrypoint) \
    TF_ACC=1 \
    go test -tags=eks ./internal/provider/... -count=1 -v -run=EKS -timeout=30m

This will run the EKS tests using your auth, and eksctl to manage the cluster.

The test will look like it's doing nothing for ~15-20 minutes, but you can check the progress by using eksctl get clusters.

When the cluster is up, you can find its kubeconfig in $TMPDIR/imagetest-<uid>, and eksctl populates the file (this takes ~10 minutes), use it to interact with the cluster:

KUBECONFIG=$TMPDIR/imagetest-<uid> kubectl get nodes

When the test completes, it should delete the cluster, but just in case it doesn't, you can delete it with:

eksctl delete cluster --name=imagetest-<uid>

You can also find the cluster in the AWS Console: https://us-west-2.console.aws.amazon.com/eks/home

To reuse the cluster instead of creating a new one each time, you can run the tests with IMAGETEST_EKS_SKIP_TEARDOWN=true.

Then, the next time you run the test, find the cluster that the last test created, and add IMAGETEST_EKS_CLUSTER=imagetest-<uid> to reuse the cluster.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd
entrypoint
entrypoint is **heavily** inspired by prow's entrypoint package: https://github.com/kubernetes-sigs/prow/tree/main/pkg/entrypoint
entrypoint is **heavily** inspired by prow's entrypoint package: https://github.com/kubernetes-sigs/prow/tree/main/pkg/entrypoint
internal
docker
docker holds useful things for interacting with docker
docker holds useful things for interacting with docker
drivers/docker_in_docker
dockerindocker is a driver that runs each test container in its _own_ dind sandbox.
dockerindocker is a driver that runs each test container in its _own_ dind sandbox.
drivers/k3s_in_docker
k3sindocker is a driver that runs each test in a pod within a k3s cluster run in docker.
k3sindocker is a driver that runs each test in a pod within a k3s cluster run in docker.
harness/pterraform
Package pterraform provides a harness that runs arbitrary terraform on a given path.
Package pterraform provides a harness that runs arbitrary terraform on a given path.
log
provider/framework
Package framework contains code related to the Terraform Plugin Framework.
Package framework contains code related to the Terraform Plugin Framework.
skip
Package skip contains logic for determining if a test should be skipped.
Package skip contains logic for determining if a test should be skipped.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL