File tree 4 files changed +26
-5
lines changed
4 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ please refer to the man pages of `terraform --help`.
39
39
40
40
## Change Log
41
41
42
+ * v0.13: Fix S3 automatic ` use_s3_path_style ` detection when setting S3_HOSTNAME or LOCALSTACK_HOSTNAME
42
43
* v0.12: Fix local endpoint overrides for Terraform AWS provider 5.9.0; fix parsing of alias and region defined as value lists
43
44
* v0.11: Minor fix to handle boolean values in S3 backend configs
44
45
* v0.10: Add support for storing state files in local S3 backends
Original file line number Diff line number Diff line change @@ -10,11 +10,12 @@ your TF config.
10
10
"""
11
11
12
12
import os
13
- import re
14
13
import sys
15
14
import glob
16
15
import subprocess
17
16
17
+ from urllib .parse import urlparse
18
+
18
19
PARENT_FOLDER = os .path .realpath (os .path .join (os .path .dirname (__file__ ), '..' ))
19
20
if os .path .isdir (os .path .join (PARENT_FOLDER , '.venv' )):
20
21
sys .path .insert (0 , PARENT_FOLDER )
@@ -212,9 +213,18 @@ def generate_s3_backend_config() -> str:
212
213
# ---
213
214
214
215
def use_s3_path_style () -> bool :
215
- """Whether to use S3 path addressing (depending on the configured S3 endpoint)"""
216
- regex = r"^[a-z]+://(localhost|[0-9.]+)(:[0-9]+)?$"
217
- return bool (re .match (regex , get_service_endpoint ("s3" )))
216
+ """
217
+ Whether to use S3 path addressing (depending on the configured S3 endpoint)
218
+ If the endpoint starts with the `s3.` prefix, LocalStack will recognize virtual host addressing. If the endpoint
219
+ does not start with it, use path style. This also allows overriding the endpoint to always use path style in case of
220
+ inter container communications in Docker.
221
+ """
222
+ try :
223
+ host = urlparse (get_service_endpoint ("s3" )).hostname
224
+ except ValueError :
225
+ host = ""
226
+
227
+ return not host .startswith ("s3." )
218
228
219
229
220
230
def get_region () -> str :
Original file line number Diff line number Diff line change 1
1
[metadata]
2
2
name = terraform-local
3
- version = 0.12
3
+ version = 0.13
4
4
url = https://github.com/localstack/terraform-local
5
5
author = LocalStack Team
6
6
Original file line number Diff line number Diff line change @@ -34,6 +34,16 @@ def test_use_s3_path_style(monkeypatch):
34
34
import_cli_code ()
35
35
assert use_s3_path_style () # noqa
36
36
37
+ # test the case where the S3_HOSTNAME could be a Docker container name
38
+ monkeypatch .setenv ("S3_HOSTNAME" , "localstack" )
39
+ import_cli_code ()
40
+ assert use_s3_path_style () # noqa
41
+
42
+ # test the case where the S3_HOSTNAME could be an arbitrary host starting with `s3.`
43
+ monkeypatch .setenv ("S3_HOSTNAME" , "s3.internal.host" )
44
+ import_cli_code ()
45
+ assert not use_s3_path_style () # noqa
46
+
37
47
38
48
def test_provider_aliases (monkeypatch ):
39
49
queue_name1 = f"q{ short_uid ()} "
You can’t perform that action at this time.
0 commit comments