azure-pipelines-tasks-terraform icon indicating copy to clipboard operation
azure-pipelines-tasks-terraform copied to clipboard

AWS - Does Terraform Init Task Support DynamoDB Backend for Locking with S3 State Files?

Open brandtaderrick opened this issue 1 year ago • 3 comments

If you want to use DynamoDB in collaboration with S3 to handle locking and state checksum management, can you do that with the TerraformCLI@0 init task? I searched around the repo, but I didn't have any luck figuring out whether this would be supported with something like "dynamo_db_table: states.locks."

  displayName: 'terraform init'
  inputs:
    command: init
    workingDirectory: $(my_terraform_templates_dir)
    # set to `aws` to use aws backend
    backendType: aws
    # service connection name, required if backendType = aws
    backendServiceAws: env_test_aws
    # s3 bucket's region, optional if provided elsewhere (i.e. inside terraform template or command options)
    backendAwsRegion: us-east-1
    # s3 bucket name, optional if provided elsewhere (i.e. inside terraform template or command options)
    backendAwsBucket: s3-trfrm-dev-eus-czp
    # s3 path to state file, optional if provided elsewhere (i.e. inside terraform template or command options)
    backendAwsKey: 'my-env-infrax/dev-infrax'```

brandtaderrick avatar May 03 '24 16:05 brandtaderrick

@piizei do you have any insights here?

jason-johnson avatar May 27 '24 15:05 jason-johnson

From what I see from the source code the parameter is not managed, but you can add the relevant options using -backend-config=key=value in commandOptions Eg:

- task: TerraformCLI@0
  displayName: 'terraform init'
  inputs:
    command: init
    workingDirectory: $(my_terraform_templates_dir)
    backendType: aws
    backendServiceAws: env_test_aws
    backendAwsRegion: us-east-1
    backendAwsBucket: s3-trfrm-dev-eus-czp
    backendAwsKey: 'my-env-infrax/dev-infrax'
    commandOptions: '-backend-config=dynamodb_table=lock_table'

igordust avatar Oct 08 '24 10:10 igordust

Hi, I am struggling a bit to store state file in S3 backend though using similar options, just want to confirm if code above does allow Apply task to add stattefile in S3?

hemantpro avatar Nov 01 '24 15:11 hemantpro