Search code examples
amazon-web-servicesterraformterraform-provider-awshashicorp

Adding retry properties to AWS batch job in terraform


I want to add retry strategy in aws_batch_job_definition of HCL. I tried using:

retry_strategy = {
  "attempts" = "2" 
}

The deployment is giving me an error

{", "\u001b[0m", "An argument named \"retry_strategy\" is not expected here. Did you mean to", "define a block of type \"retry_strategy\"?", "\u001b[0m\u001b[0m"]}

What am I doing wrong?


Solution

  • I don't have an entire code block to show how the resource would look like, but the error is self-explanatory. What you are trying to do is assign a value to an argument named retry_stratagy, which is actually a block (not argument), so the final outlook is:

     retry_strategy {
        attempts = 2 
     }
    

    An example of the resource block with only required arguments:

    resource "aws_batch_job_definition" "name" {
      name = "value"
      type = "container"
    
      retry_strategy {
        attempts = 2
      }
      
    }
    

    Output of terraform plan with the above configuration:

    Terraform will perform the following actions:
    
      # aws_batch_job_definition.name will be created
      + resource "aws_batch_job_definition" "name" {
          + arn            = (known after apply)
          + id             = (known after apply)
          + name           = "value"
          + propagate_tags = false
          + revision       = (known after apply)
          + tags_all       = (known after apply)
          + type           = "container"
    
          + retry_strategy {
              + attempts = 2
            }
        }