Skip to content

Commit

Permalink
Merge pull request #372 from lorengordon/tftest-overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
lorengordon authored Jan 7, 2022
2 parents ed104d0 + a830953 commit 987dbe6
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.19.7
current_version = 0.21.0
commit = True
message = Bumps version to {new_version}
tag = False
Expand Down
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ updates:
schedule:
interval: weekly
open-pull-requests-limit: 10
- package-ecosystem: pip
directory: "/tests/terraform_pytest"
schedule:
interval: weekly
open-pull-requests-limit: 10
- package-ecosystem: docker
directory: "/"
schedule:
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

### 0.20.0

**Released**: 2022.01.06

**Commit Delta**: [Change from 0.19.7 release](https://github.com/plus3it/tardigrade-ci/compare/0.19.7..0.20.0)

**Summary**:

* Uses override file to inject mockstack config for aws provider. Allows test configs
to manage their aws provider config entirely, including any argument supported
by the aws provider. Test configs should now always work without modification
for the "--nomock" use case, running against real aws endpoints. For more,
see [PR #372](https://github.com/plus3it/tardigrade-ci/pull/372).
* Removes pytest argument `--alias`.
* Skips tftest cleanup on exit, so the tfstate remains intact. This is useful if
there were errors when tftest ran the destroy action, as it allows us to manually
inspect the state and re-run `terraform destroy`.

* Updates tool versions:
* tftest 1.6.3

### 0.19.7

**Released**: 2022.01.03
Expand Down
2 changes: 0 additions & 2 deletions INTEGRATION_TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ be located in the directory `tests` off the repo\'s root directory.
| -------------------------------- | --------------------------------------- |
| INTEGRATION_TEST_BASE_IMAGE_NAME | $(basename $PWD)-integration-test |
| ONLY_MOTO | False; adds "--only-moto" to PYTEST_ARGS |
| PROVIDER_ALIAS | No default; adds "--alias \<alias\>" to PYTEST_ARGS |
| PYTEST_ARGS | |
| TERRAFORM_PYTEST_DIR | $PWD/tests/terraform/pytest |

Expand All @@ -45,7 +44,6 @@ PYTEST_ARGS.
| Command line option | Description |
| ------------------- | ----------------------------------------------- |
| --nomock | Use AWS, not mocked AWS services. Takes precedence over the "--only-moto" option. |
| --alias ALIAS | Add a provider ALIAS to the Terraform test |
| --alternate-profile | Configure an alternate profile in addition to default profile |
| --only-moto | Use moto ports only for mock AWS services |
| --tf-dir=TF_DIR | Directory of Terraform files under test; default: './tests' |
Expand Down
15 changes: 4 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,14 @@ ec/install:
$(@D) --version
@ echo "[$@]: Completed successfully!"

install/pip/% install/pip_pkg_with_no_cli/% pytest/install: PIP ?= $(if $(shell pyenv which $(PYTHON) 2> /dev/null),pip,$(PYTHON) -m pip)
install/pip/%: PKG_VERSION_CMD ?= $* --version
install/pip/%: PIP ?= $(if $(shell pyenv which $(PYTHON) 2> /dev/null),pip,$(PYTHON) -m pip)
install/pip/%: | $(BIN_DIR) guard/env/PYPI_PKG_NAME
@ echo "[$@]: Installing $*..."
$(PIP) install $(PYPI_PKG_NAME)
$(PKG_VERSION_CMD)
@ echo "[$@]: Completed successfully!"

install/pip_pkg_with_no_cli/%: PIP ?= $(if $(shell pyenv which $(PYTHON) 2> /dev/null),pip,$(PYTHON) -m pip)
install/pip_pkg_with_no_cli/%: | guard/env/PYPI_PKG_NAME
@ echo "[$@]: Installing $*..."
$(PIP) install $(PYPI_PKG_NAME)
Expand All @@ -202,13 +201,8 @@ black/install: BLACK_VERSION ?= $(call match_pattern_in_file,$(TARDIGRADE_CI_PYT
black/install:
@ $(MAKE) install/pip/$(@D) PYPI_PKG_NAME='$(@D)==$(BLACK_VERSION)'

tftest/install: TFTEST_VERSION ?= $(call match_pattern_in_file,$(TARDIGRADE_CI_PYTHON_TOOLS),'tftest==','$(SEMVER_PATTERN)')
tftest/install:
@ $(MAKE) install/pip_pkg_with_no_cli/$(@D) PYPI_PKG_NAME='$(@D)==$(TFTEST_VERSION)'

pytest/install: PYTEST_VERSION ?= $(call match_pattern_in_file,$(TARDIGRADE_CI_PYTHON_TOOLS),'^pytest==','$(SEMVER_PATTERN)')
pytest/install:
@ $(MAKE) install/pip/$(@D) PYPI_PKG_NAME='$(@D)==$(PYTEST_VERSION)'
@ $(PIP) install -r $(TERRAFORM_PYTEST_DIR)/requirements.txt

pylint/install: PYLINT_VERSION ?= $(call match_pattern_in_file,$(TARDIGRADE_CI_PYTHON_TOOLS),'pylint==','$(SEMVER_PATTERN)')
pylint/install:
Expand Down Expand Up @@ -309,12 +303,11 @@ python/format:

# Run pytests, typically for unit tests.
PYTEST_ARGS ?=
PYTEST_ALIAS_ARG ?= $(if $(PROVIDER_ALIAS),--alias $(PROVIDER_ALIAS),)
PYTEST_ONLY_MOTO_ARG ?= $(if $(ONLY_MOTO),--only-moto,)
pytest/%: | guard/program/pytest
pytest/%:
@ echo "[$@] Starting Python tests found under the directory \"$*\""
pytest $* $(PYTEST_ARGS) $(PYTEST_ALIAS_ARG) $(PYTEST_ONLY_MOTO_ARG)
pytest $* $(PYTEST_ARGS) $(PYTEST_ONLY_MOTO_ARG)
@ echo "[$@]: Tests executed!"

## Lints terraform files
Expand Down Expand Up @@ -514,7 +507,7 @@ project/validate:
@ echo "[$@]: Target test folder validation successful"

install: terragrunt/install terraform/install shellcheck/install terraform-docs/install
install: bats/install black/install pylint/install pylint-pytest/install pydocstyle/install pytest/install tftest/install
install: bats/install black/install pylint/install pylint-pytest/install pydocstyle/install pytest/install
install: ec/install yamllint/install cfn-lint/install yq/install bumpversion/install jq/install
install: docker-compose/install rclone/install packer/install

Expand Down
4 changes: 0 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,4 @@ pylint==2.12.2

pylint-pytest==1.1.2

pytest==6.2.5

tftest==1.6.2

yamllint==1.26.3
3 changes: 0 additions & 3 deletions tests/terraform_pytest/aws.tf

This file was deleted.

11 changes: 0 additions & 11 deletions tests/terraform_pytest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ def pytest_addoption(parser):
default=str(Path(Path.cwd() / "tests")),
help="Directory of Terraform files under test; default: './tests'",
)
parser.addoption(
"--alias",
action="store",
help="Name of Terraform provider alias to include in test",
)
parser.addoption(
"--only-moto",
action="store_true",
Expand Down Expand Up @@ -101,12 +96,6 @@ def tf_dir(request):
return Path(terraform_dir).resolve()


@pytest.fixture(scope="session")
def provider_alias(request):
"""Return name of alias for provider, if one was given."""
return request.config.getoption("--alias")


@pytest.fixture(scope="session")
def only_moto(request):
"""Return True if only moto ports are to be used for mock services."""
Expand Down
37 changes: 0 additions & 37 deletions tests/terraform_pytest/mockstack.tf

This file was deleted.

20 changes: 0 additions & 20 deletions tests/terraform_pytest/mockstack_variables.tf

This file was deleted.

10 changes: 10 additions & 0 deletions tests/terraform_pytest/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This requirements.txt file is used to let Dependabot manage pinned versions of
# tools that will be installed using the target `make pytest/install`

# Keep this list in alphabetical order, with a single blank line between each package

pytest==6.2.5

python-hcl2==3.0.1

tftest==1.6.3
Loading

0 comments on commit 987dbe6

Please sign in to comment.