@@ -221,7 +221,7 @@ def generate_s3_backend_config() -> str:
221
221
"key" : "terraform.tfstate" ,
222
222
"dynamodb_table" : "tf-test-state" ,
223
223
"region" : get_region (),
224
- "use_path_style" : "true " ,
224
+ "use_path_style" : "false " ,
225
225
"endpoints" : {
226
226
"s3" : get_service_endpoint ("s3" ),
227
227
"iam" : get_service_endpoint ("iam" ),
@@ -244,6 +244,11 @@ def generate_s3_backend_config() -> str:
244
244
backend_config ["endpoints" ] = {
245
245
k : backend_config ["endpoints" ].get (k ) or v
246
246
for k , v in configs ["endpoints" ].items ()}
247
+ # If the endpoint is configured in the backend we use that endpoint
248
+ # otherwise we will use the default created for the provider. Note that the user
249
+ # can still override this value with `use_path_style`in backend tf config
250
+ if use_s3_path_style (backend_config .get ("endpoints" , {}).get ("s3" )):
251
+ backend_config ["use_path_style" ] = "true"
247
252
configs .update (backend_config )
248
253
if not DRY_RUN :
249
254
get_or_create_bucket (configs ["bucket" ])
@@ -294,15 +299,17 @@ def check_override_file(providers_file: str) -> None:
294
299
# AWS CLIENT UTILS
295
300
# ---
296
301
297
- def use_s3_path_style () -> bool :
302
+ def use_s3_path_style (endpoint : str = "" ) -> bool :
298
303
"""
299
304
Whether to use S3 path addressing (depending on the configured S3 endpoint)
300
305
If the endpoint starts with the `s3.` prefix, LocalStack will recognize virtual host addressing. If the endpoint
301
306
does not start with it, use path style. This also allows overriding the endpoint to always use path style in case of
302
307
inter container communications in Docker.
303
308
"""
304
309
try :
305
- host = urlparse (get_service_endpoint ("s3" )).hostname
310
+ if endpoint :
311
+ endpoint = add_http_protocol (endpoint )
312
+ host = urlparse (endpoint or get_service_endpoint ("s3" )).hostname
306
313
except ValueError :
307
314
host = ""
308
315
@@ -348,15 +355,20 @@ def deactivate_access_key(access_key: str) -> str:
348
355
return "L" + access_key [1 :] if access_key [0 ] == "A" else access_key
349
356
350
357
358
+ def add_http_protocol (url : str ) -> str :
359
+ """Add the http:// protocal if not found in the url"""
360
+ if "://" not in url :
361
+ return f"http://{ url } "
362
+ return url
363
+
364
+
351
365
def get_service_endpoint (service : str ) -> str :
352
366
"""Get the service endpoint URL for the given service name"""
353
367
# allow configuring a custom endpoint via the environment
354
368
env_name = f"{ service .replace ('-' , '_' ).upper ().strip ()} _ENDPOINT"
355
369
env_endpoint = os .environ .get (env_name , "" ).strip ()
356
370
if env_endpoint :
357
- if "://" not in env_endpoint :
358
- env_endpoint = f"http://{ env_endpoint } "
359
- return env_endpoint
371
+ return add_http_protocol (env_endpoint )
360
372
361
373
# some services need specific hostnames
362
374
hostname = LOCALSTACK_HOSTNAME
0 commit comments