Skip to content

Commit 0b2d155

Browse files
authored
Aws_endpoint_url_var (#35)
1 parent 38be70b commit 0b2d155

File tree

7 files changed

+31
-22
lines changed

7 files changed

+31
-22
lines changed

Diff for: .github/workflows/build.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ on:
1010
name: Build and Test
1111
jobs:
1212
build_test:
13-
timeout-minutes: 10
13+
timeout-minutes: 30
1414
runs-on: ubuntu-latest
1515
env:
1616
AWS_DEFAULT_REGION: us-east-1
17+
DNS_ADDRESS: 127.0.0.1
1718

1819
steps:
1920
- name: Check out code
2021
uses: actions/checkout@v3
2122
- name: Pull LocalStack Docker image
2223
run: docker pull localstack/localstack &
23-
- name: Set up Python 3.10
24+
- name: Set up Python 3.11
2425
uses: actions/setup-python@v2
2526
with:
26-
python-version: '3.10.5'
27+
python-version: '3.11'
2728
- name: Install dependencies
2829
run: make install
2930
- name: Run code linter

Diff for: .gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Custom
2+
.envrc
3+
.env
4+
15
.DS_Store
26
*.egg-info/
37
dist/
@@ -115,4 +119,4 @@ fabric.properties
115119
.history
116120
.ionide
117121

118-
# End of https://www.toptal.com/developers/gitignore/api/pycharm+all,visualstudiocode
122+
# End of https://www.toptal.com/developers/gitignore/api/pycharm+all,visualstudiocode

Diff for: Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ test: ## Run unit/integration tests
1919

2020
publish: ## Publish the library to the central PyPi repository
2121
# build and upload archive
22-
($(VENV_RUN) && pip install setuptools && ./setup.py sdist && twine upload dist/*)
22+
($(VENV_RUN) && pip install setuptools twine && ./setup.py sdist && twine upload dist/*)
2323

2424
clean: ## Clean up
2525
rm -rf $(VENV_DIR)
26+
rm -rf dist/*
2627

2728
.PHONY: clean publish install usage lint test

Diff for: README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ pip install terraform-local
2525

2626
The following environment variables can be configured:
2727
* `TF_CMD`: Terraform command to call (default: `terraform`)
28-
* `LOCALSTACK_HOSTNAME`: host name of the target LocalStack instance
29-
* `EDGE_PORT`: port number of the target LocalStack instance
28+
* `AWS_ENDPOINT_URL`: hostname and port of the target LocalStack instance
29+
* `LOCALSTACK_HOSTNAME`: __(Deprecated)__ host name of the target LocalStack instance
30+
* `EDGE_PORT`: __(Deprecated)__ port number of the target LocalStack instance
3031
* `S3_HOSTNAME`: special hostname to be used to connect to LocalStack S3 (default: `s3.localhost.localstack.cloud`)
3132
* `USE_EXEC`: whether to use `os.exec` instead of `subprocess.Popen` (try using this in case of I/O issues)
3233
* `<SERVICE>_ENDPOINT`: setting a custom service endpoint, e.g., `COGNITO_IDP_ENDPOINT=http://example.com`
@@ -47,6 +48,7 @@ please refer to the man pages of `terraform --help`.
4748

4849
## Change Log
4950

51+
* v0.16.0: Introducing semantic versioning and AWS_ENDPOINT_URL variable
5052
* v0.15: Update endpoint overrides for Terraform AWS provider 5.22.0
5153
* v0.14: Add support to multi-account environments
5254
* v0.13: Fix S3 automatic `use_s3_path_style` detection when setting S3_HOSTNAME or LOCALSTACK_HOSTNAME

Diff for: bin/tflocal

+9-8
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,24 @@ import subprocess
1616

1717
from urllib.parse import urlparse
1818

19-
PARENT_FOLDER = os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))
20-
if os.path.isdir(os.path.join(PARENT_FOLDER, '.venv')):
19+
PARENT_FOLDER = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))
20+
if os.path.isdir(os.path.join(PARENT_FOLDER, ".venv")):
2121
sys.path.insert(0, PARENT_FOLDER)
2222

2323
from localstack_client import config # noqa: E402
2424
import hcl2 # noqa: E402
2525

2626
DEFAULT_REGION = "us-east-1"
2727
DEFAULT_ACCESS_KEY = "test"
28+
AWS_ENDPOINT_URL = os.environ.get("AWS_ENDPOINT_URL")
2829
CUSTOMIZE_ACCESS_KEY = str(os.environ.get("CUSTOMIZE_ACCESS_KEY")).strip().lower() in ["1", "true"]
2930
LOCALHOST_HOSTNAME = "localhost.localstack.cloud"
3031
S3_HOSTNAME = os.environ.get("S3_HOSTNAME") or f"s3.{LOCALHOST_HOSTNAME}"
3132
USE_EXEC = str(os.environ.get("USE_EXEC")).strip().lower() in ["1", "true"]
3233
TF_CMD = os.environ.get("TF_CMD") or "terraform"
3334
LS_PROVIDERS_FILE = os.environ.get("LS_PROVIDERS_FILE") or "localstack_providers_override.tf"
34-
LOCALSTACK_HOSTNAME = os.environ.get("LOCALSTACK_HOSTNAME") or "localhost"
35-
EDGE_PORT = int(os.environ.get("EDGE_PORT") or 4566)
35+
LOCALSTACK_HOSTNAME = urlparse(AWS_ENDPOINT_URL).hostname or os.environ.get("LOCALSTACK_HOSTNAME") or "localhost"
36+
EDGE_PORT = int(urlparse(AWS_ENDPOINT_URL).port or os.environ.get("EDGE_PORT") or 4566)
3637
TF_PROVIDER_CONFIG = """
3738
provider "aws" {
3839
access_key = "<access_key>"
@@ -337,12 +338,12 @@ def get_or_create_ddb_table(table_name: str, region: str = None):
337338
def parse_tf_files() -> dict:
338339
"""Parse the local *.tf files and return a dict of <filename> -> <resource_dict>"""
339340
result = {}
340-
for _file in glob.glob('*.tf'):
341+
for _file in glob.glob("*.tf"):
341342
try:
342-
with open(_file, 'r') as fp:
343+
with open(_file, "r") as fp:
343344
result[_file] = hcl2.load(fp)
344345
except Exception as e:
345-
print(f"Unable to parse '{_file}' as HCL file: {e}")
346+
print(f'Unable to parse "{_file}" as HCL file: {e}')
346347
return result
347348

348349

@@ -408,5 +409,5 @@ def main():
408409
os.remove(config_file)
409410

410411

411-
if __name__ == '__main__':
412+
if __name__ == "__main__":
412413
main()

Diff for: setup.cfg

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = terraform-local
3-
version = 0.15
3+
version = 0.16.0
44
url = https://github.com/localstack/terraform-local
55
author = LocalStack Team
66
author_email = [email protected]
@@ -14,6 +14,7 @@ classifiers =
1414
Programming Language :: Python :: 3.8
1515
Programming Language :: Python :: 3.9
1616
Programming Language :: Python :: 3.10
17+
Programming Language :: Python :: 3.11
1718
License :: OSI Approved :: Apache Software License
1819
Topic :: Software Development :: Testing
1920

Diff for: tests/test_apply.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,11 @@ def test_access_key_override_by_profile(monkeypatch, profile_name: str):
5252
monkeypatch.setenv("CUSTOMIZE_ACCESS_KEY", "1")
5353
access_key = mock_access_key()
5454
bucket_name = short_uid()
55-
credentials = """
56-
[%s]
57-
aws_access_key_id = %s
58-
aws_secret_access_key = test
59-
region = eu-west-1
60-
""" % (profile_name, access_key)
55+
credentials = """[%s]
56+
aws_access_key_id = %s
57+
aws_secret_access_key = test
58+
region = eu-west-1
59+
""" % (profile_name, access_key)
6160
with tempfile.TemporaryDirectory() as temp_dir:
6261
credentials_file = os.path.join(temp_dir, "credentials")
6362
with open(credentials_file, "w") as f:

0 commit comments

Comments
 (0)