@@ -55,7 +55,8 @@ LOCALSTACK_HOSTNAME = (
5555 or os .environ .get ("LOCALSTACK_HOSTNAME" )
5656 or "localhost"
5757)
58- EDGE_PORT = int (urlparse (AWS_ENDPOINT_URL ).port or os .environ .get ("EDGE_PORT" ) or 4566 )
58+ EDGE_PORT = int (
59+ urlparse (AWS_ENDPOINT_URL ).port or os .environ .get ("EDGE_PORT" ) or 4566 )
5960TF_VERSION : Optional [version .Version ] = None
6061TF_PROVIDER_CONFIG = """
6162provider "aws" {
@@ -186,7 +187,8 @@ def create_provider_config_file(provider_file_path: str, provider_aliases=None)
186187 for provider in provider_aliases :
187188 provider_config = TF_PROVIDER_CONFIG .replace (
188189 "<access_key>" ,
189- get_access_key (provider ) if CUSTOMIZE_ACCESS_KEY else DEFAULT_ACCESS_KEY ,
190+ get_access_key (
191+ provider ) if CUSTOMIZE_ACCESS_KEY else DEFAULT_ACCESS_KEY ,
190192 )
191193 endpoints = "\n " .join (
192194 [f' { s } = "{ get_service_endpoint (s )} "' for s in services ]
@@ -288,7 +290,7 @@ def generate_s3_backend_config() -> str:
288290 # note: default values, updated by `backend_config` further below...
289291 "bucket" : "tf-test-state" ,
290292 "key" : "terraform.tfstate" ,
291- "dynamodb_table " : "tf-test-state" ,
293+ "use_lockfile " : True ,
292294 "region" : get_region (),
293295 "skip_credentials_validation" : True ,
294296 "skip_metadata_api_check" : True ,
@@ -332,12 +334,16 @@ def generate_s3_backend_config() -> str:
332334 for k , v in configs ["endpoints" ].items ()
333335 }
334336 backend_config ["access_key" ] = (
335- get_access_key (backend_config ) if CUSTOMIZE_ACCESS_KEY else DEFAULT_ACCESS_KEY
337+ get_access_key (
338+ backend_config ) if CUSTOMIZE_ACCESS_KEY else DEFAULT_ACCESS_KEY
336339 )
337340 configs .update (backend_config )
338341 if not DRY_RUN :
339342 get_or_create_bucket (configs ["bucket" ])
340- get_or_create_ddb_table (configs ["dynamodb_table" ], region = configs ["region" ])
343+ if "dynamodb_table" in configs :
344+ del configs ["use_lockfile" ]
345+ get_or_create_ddb_table (
346+ configs ["dynamodb_table" ], region = configs ["region" ])
341347 result = TF_S3_BACKEND_CONFIG
342348 config_options = ""
343349 for key , value in sorted (configs .items ()):
@@ -491,7 +497,8 @@ def get_or_create_bucket(bucket_name: str):
491497 region = s3_client .meta .region_name
492498 kwargs = {}
493499 if region != "us-east-1" :
494- kwargs = {"CreateBucketConfiguration" : {"LocationConstraint" : region }}
500+ kwargs = {"CreateBucketConfiguration" : {
501+ "LocationConstraint" : region }}
495502 return s3_client .create_bucket (Bucket = bucket_name , ** kwargs )
496503
497504
@@ -505,7 +512,8 @@ def get_or_create_ddb_table(table_name: str, region: str = None):
505512 TableName = table_name ,
506513 BillingMode = "PAY_PER_REQUEST" ,
507514 KeySchema = [{"AttributeName" : "LockID" , "KeyType" : "HASH" }],
508- AttributeDefinitions = [{"AttributeName" : "LockID" , "AttributeType" : "S" }],
515+ AttributeDefinitions = [
516+ {"AttributeName" : "LockID" , "AttributeType" : "S" }],
509517 )
510518
511519
@@ -615,7 +623,8 @@ def main():
615623 if not TF_VERSION :
616624 raise ValueError
617625 except (FileNotFoundError , ValueError ) as e :
618- print (f"Unable to determine version. See error message for details: { e } " )
626+ print (
627+ f"Unable to determine version. See error message for details: { e } " )
619628 exit (1 )
620629
621630 config_override_files = []
0 commit comments