@@ -205,6 +205,43 @@ def test_s3_backend():
205205 assert result ["ResponseMetadata" ]["HTTPStatusCode" ] == 200
206206
207207
208+ def test_s3_backend_state_lock_default ():
209+ state_bucket = f"tf-state-{ short_uid ()} "
210+ bucket_name = f"bucket-{ short_uid ()} "
211+ state_region = "us-west-1"
212+ dynamodb_client = client ("dynamodb" , region_name = state_region )
213+ table_amount = len (dynamodb_client .list_tables ()["TableNames" ])
214+ config = """
215+ terraform {
216+ backend "s3" {
217+ bucket = "%s"
218+ key = "terraform.tfstate"
219+ region = "%s"
220+ skip_credentials_validation = true
221+ }
222+ }
223+ resource "aws_s3_bucket" "test-bucket" {
224+ bucket = "%s"
225+ }
226+ """ % (state_bucket , state_region , bucket_name )
227+ deploy_tf_script (config )
228+
229+ # assert that bucket with state file exists
230+ s3 = client ("s3" , region_name = state_region )
231+ result = s3 .list_objects (Bucket = state_bucket )
232+ keys = [obj ["Key" ] for obj in result ["Contents" ]]
233+ assert "terraform.tfstate" in keys
234+
235+ # assert that DynamoDB table with state file locks has not been created by default
236+ result = dynamodb_client .list_tables ()
237+ assert len (result ["TableNames" ]) == table_amount
238+
239+ # assert that S3 resource has been created
240+ s3 = client ("s3" )
241+ result = s3 .head_bucket (Bucket = bucket_name )
242+ assert result ["ResponseMetadata" ]["HTTPStatusCode" ] == 200
243+
244+
208245def test_dry_run (monkeypatch ):
209246 monkeypatch .setenv ("DRY_RUN" , "1" )
210247 state_bucket = "tf-state-dry-run"
0 commit comments