-
Notifications
You must be signed in to change notification settings - Fork 36
add terraform-local version when using version flag #84
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. 👍
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 Hurray for extra safety here! 🚀
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks! made me think I'll update those to use |
||
|
|
||
| config_override_files = [] | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -674,6 +674,23 @@ 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: | ||
| # we need the `terraform init` command to create a lock file, so it cannot be a `DRY_RUN` | ||
|
||
| 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 | ||
| ### | ||
|
|
||
There was a problem hiding this comment.
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! 🙏