Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ ADDITIONAL_TF_OVERRIDE_LOCATIONS=/path/to/module1,path/to/module2 tflocal plan

## Change Log

* v0.24.0: Add support to return `terraform-local` version when calling `tflocal -version` and fix AWS provider detection
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding the previous pr changelog as well! 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this doesn't sound clear... lmk if you find something better, I'd happily take any suggestion 😅

* v0.23.1: Fix endpoint overrides for Terraform AWS provider >= 6.0.0-beta2
* v0.23.0: Add support for `terraform_remote_state` with `s3` backend to read the state stored in local S3 backend; fix S3 backend config detection with multiple Terraform blocks
* v0.22.0: Fix S3 backend forcing DynamoDB State Lock to be enabled by default
Expand Down
18 changes: 16 additions & 2 deletions bin/tflocal
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,11 @@ def get_provider_version_from_lock_file() -> Optional[version.Version]:
AWS_PROVIDER_VERSION = version.parse(provider_version)


def get_tf_local_version():
from importlib.metadata import version
return version("terraform-local")
Comment on lines +643 to +645
Copy link
Member

Choose a reason for hiding this comment

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

I agree that this seems safe. It will find the version that is currently available in the venv, so we won't have issues with multiple install of tflocal.

I have tested install with pipx, with pip in a venv and my hybrid dev env, and all seem to give proper result. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

awesome, thanks a lot for taking the time to test extra scenarios 🙏



def is_service_endpoint_supported(service_name: str) -> bool:
if service_name not in VERSIONED_SERVICE_EXCLUSIONS or not AWS_PROVIDER_VERSION:
return True
Expand Down Expand Up @@ -728,8 +733,17 @@ def main():
print(f"Unable to determine version. See error message for details: {e}")
exit(1)

if len(sys.argv) > 1 and sys.argv[1] != "init":
get_provider_version_from_lock_file()
if len(sys.argv) > 1:
if sys.argv[1] != "init":
get_provider_version_from_lock_file()
if sys.argv[1] in ("--version", "-v", "-version"):
try:
# the version flag could be something else than the 1st argument, it is possible to do
# `terraform init -version` and it will return the version only without init, but we should probably
# only support the easy case
print(f"terraform-local v{get_tf_local_version()}", file=sys.stderr)
except Exception:
pass
Comment on lines +745 to +746
Copy link
Member

Choose a reason for hiding this comment

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

🎉 Hurray for extra safety here! 🚀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks! made me think I'll update those to use contextlib.suppress, but this will be for a follow up 👌


config_override_files = []

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = terraform-local
version = 0.23.1
version = 0.24.0
url = https://github.com/localstack/terraform-local
author = LocalStack Team
author_email = info@localstack.cloud
Expand Down
16 changes: 16 additions & 0 deletions tests/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,22 @@ def check_override_file_content_for_alias(override_file):
return True


@pytest.mark.parametrize("version_flag", ["--version", "-v", "-version"])
def test_version_command(monkeypatch, version_flag):
def _run(cmd, **kwargs):
kwargs["stderr"] = subprocess.STDOUT
return subprocess.check_output(cmd, **kwargs)

with tempfile.TemporaryDirectory(delete=True) as temp_dir:
output = _run([TFLOCAL_BIN, version_flag], cwd=temp_dir, env=dict(os.environ))
assert b"terraform-local v" in output

monkeypatch.setenv("DRY_RUN", "1")
output = _run([TFLOCAL_BIN, version_flag], cwd=temp_dir, env=dict(os.environ))

assert b"terraform-local v" in output


###
# UTIL FUNCTIONS
###
Expand Down