Skip to content

Commit

Permalink
refactors testing var subst, abstract out core run logic, add jsonpat…
Browse files Browse the repository at this point in the history
…h expression validation (#44)
  • Loading branch information
marshallford authored Jul 26, 2024
1 parent b5e28dc commit 1369221
Show file tree
Hide file tree
Showing 42 changed files with 678 additions and 335 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ jobs:
fail-fast: false
matrix:
terraform:
- 1.6.*
- 1.7.*
- 1.8.*
- 1.9.*
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.8.*
terraform_version: 1.9.*
terraform_wrapper: false
- name: Setup external dependencies
run: make deps
Expand Down
6 changes: 3 additions & 3 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ endif
DOCKER := docker
DOCKER_RUN := $(DOCKER) run $(DOCKER_FLAGS)

EDITORCONFIG_CHECKER_VERSION ?= 2.7.2
EDITORCONFIG_CHECKER := $(DOCKER_RUN) -v=$(CURDIR):/check docker.io/mstruebing/editorconfig-checker:$(EDITORCONFIG_CHECKER_VERSION)
EDITORCONFIG_CHECKER_VERSION ?= 3.0.3
EDITORCONFIG_CHECKER := $(DOCKER_RUN) -v=$(CURDIR):/check docker.io/mstruebing/editorconfig-checker:v$(EDITORCONFIG_CHECKER_VERSION)

SHELLCHECK_VERSION ?= 0.10.0
SHELLCHECK := $(DOCKER_RUN) -v=$(CURDIR):/mnt docker.io/koalaman/shellcheck:v$(SHELLCHECK_VERSION)

YAMLLINT_VERSION ?= 0.31.0
YAMLLINT_VERSION ?= 0.31.3
YAMLLINT := $(DOCKER_RUN) -v=$(CURDIR):/code docker.io/pipelinecomponents/yamllint:$(YAMLLINT_VERSION) yamllint

GOLANGCI_LINT_VERSION ?= 1.59.1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Run Ansible playbooks within Ansible execution environments using Terraform.
| Release | Ansible Navigator | Terraform |
|:--------:|:-----------------:|:---------:|
| < v1.0.0 | >= 3.5.0 | >= 1.6.0 |
| < v1.0.0 | >= 24.7.0 | >= 1.7.0 |

## Development Requirements

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/navigator_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ Read-Only:

Optional:

- `container_engine` (String) [Container engine](https://ansible.readthedocs.io/projects/navigator/settings/#container-engine) responsible for running the execution environment container image. Options: `auto`, `podman`, `docker`. Defaults to `auto`.
- `container_engine` (String) [Container engine](https://ansible.readthedocs.io/projects/navigator/settings/#container-engine) responsible for running the execution environment container image. Options: `podman`, `docker`, `auto`. Defaults to `auto`.
- `container_options` (List of String) [Extra parameters](https://ansible.readthedocs.io/projects/navigator/settings/#container-options) passed to the container engine command.
- `environment_variables_pass` (List of String) Existing environment variables to be [passed](https://ansible.readthedocs.io/projects/navigator/settings/#pass-environment-variable) through to and set within the execution environment.
- `environment_variables_set` (Map of String) Environment variables to be [set](https://ansible.readthedocs.io/projects/navigator/settings/#set-environment-variable) within the execution environment. By default `ANSIBLE_TF_OPERATION` is set to the current CRUD operation (`create`, `update`, `delete`).
- `image` (String) Name of the execution environment container [image](https://ansible.readthedocs.io/projects/navigator/settings/#execution-environment-image). Defaults to `ghcr.io/ansible/community-ansible-dev-tools:v24.7.0`.
- `image` (String) Name of the execution environment container [image](https://ansible.readthedocs.io/projects/navigator/settings/#execution-environment-image). Defaults to `ghcr.io/ansible/community-ansible-dev-tools:v24.7.2`.
- `pull_arguments` (List of String) Additional [parameters](https://ansible.readthedocs.io/projects/navigator/settings/#pull-arguments) that should be added to the pull command when pulling an execution environment container image from a container registry.
- `pull_policy` (String) Container image [pull policy](https://ansible.readthedocs.io/projects/navigator/settings/#pull-policy). Defaults to `tag`.

Expand Down
2 changes: 1 addition & 1 deletion examples/complete/aws/.terraform-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.1
1.9.3
2 changes: 1 addition & 1 deletion examples/complete/aws/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 1.6.0"
required_version = ">= 1.7.0"
required_providers {
aws = {
source = "hashicorp/aws"
Expand Down
2 changes: 1 addition & 1 deletion examples/complete/libvirt/.terraform-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.1
1.9.3
2 changes: 1 addition & 1 deletion examples/complete/libvirt/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 1.6.0"
required_version = ">= 1.7.0"
required_providers {
libvirt = {
source = "dmacvicar/libvirt"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/hashicorp/terraform-plugin-testing v1.9.0
golang.org/x/crypto v0.25.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/client-go v0.30.2
k8s.io/client-go v0.30.3
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -290,5 +290,5 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/client-go v0.30.2 h1:sBIVJdojUNPDU/jObC+18tXWcTJVcwyqS9diGdWHk50=
k8s.io/client-go v0.30.2/go.mod h1:JglKSWULm9xlJLx4KCkfLLQ7XwtlbflV6uFFSHTMgVs=
k8s.io/client-go v0.30.3 h1:bHrJu3xQZNXIi8/MoxYtZBBWQQXwy16zqJwloXXfD3k=
k8s.io/client-go v0.30.3/go.mod h1:8d4pf8vYu665/kUbsxWAQ/JDBNWqfFeZnvFiVdmx89U=
22 changes: 17 additions & 5 deletions internal/provider/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,23 @@ import (
"testing"

"github.com/gliderlabs/ssh"
"github.com/hashicorp/terraform-plugin-testing/config"
gossh "golang.org/x/crypto/ssh"
)

const (
navigatorProgramPath = "../../.venv/bin/ansible-navigator" // TODO improve
)

func testAccDefaultConfigVariables(t *testing.T) config.Variables {
t.Helper()

return config.Variables{
"base_run_directory": config.StringVariable(t.TempDir()),
"ansible_navigator_binary": config.StringVariable(navigatorProgramPath),
}
}

func testAccLookPath(t *testing.T, file string) string {
t.Helper()

Expand Down Expand Up @@ -54,22 +68,20 @@ func testAccPrependProgramsToPath(t *testing.T) {
t.Setenv("PATH", fmt.Sprintf("%s%c%s", filepath.Dir(testAccAbs(t, navigatorProgramPath)), os.PathListSeparator, os.Getenv("PATH")))
}

func testAccResource(t *testing.T, name string, format ...any) string {
func testAccFile(t *testing.T, name string) string {
t.Helper()

baseRunDirectory := t.TempDir()

providerData, err := os.ReadFile(filepath.Join("testdata", "provider.tf"))
if err != nil {
t.Fatal(err)
}

resourceData, err := os.ReadFile(filepath.Join("testdata", fmt.Sprintf("%s.tf", name)))
fileData, err := os.ReadFile(filepath.Join("testdata", fmt.Sprintf("%s.tf", name)))
if err != nil {
t.Fatal(err)
}

return fmt.Sprintf(string(providerData), baseRunDirectory) + fmt.Sprintf(string(resourceData), format...)
return string(fileData) + string(providerData)
}

func sshKeygen(t *testing.T) (string, string) {
Expand Down
Loading

0 comments on commit 1369221

Please sign in to comment.