0
votes

I am trying to import an aws_glue_trigger into my terraform state so I can see how this looks in the state file and create the full resource definition to go with it as a primer for doing all our ETL stuff in terraform.

I have imported the state with an empty resource holder fine, but I am unable to work out how the list syntax is meant to work in the resource definition.

For example in my state I have a trigger with a predicate with 3 conditions and a logical underneath it, which on completion of JOBS 1, 2 & 3 will run EXAMPLE_CRAWLER - relatively straightforward:-

{
  "mode": "managed",
  "type": "aws_glue_trigger",
  "name": "EXAMPLE_TRIGGER",
  "provider": "provider.aws",
  "instances": [
    {
      "schema_version": 0,
      "attributes": {
        "actions": [
          {
            "arguments": {},
            "crawler_name": "EXAMPLE_CRAWLER",
            "job_name": "",
            "timeout": 0
          }
        ],
        "arn": "arn:SOMEARN",
        "description": "",
        "enabled": true,
        "id": "EXAMPLE_TRIGGER",
        "name": "EXAMPLE_TRIGGER",
        "predicate": [
          {
            "conditions": [
              {
                "crawl_state": "",
                "crawler_name": "",
                "job_name": "JOB1",
                "logical_operator": "EQUALS",
                "state": "SUCCEEDED"
              },
              {
                "crawl_state": "",
                "crawler_name": "",
                "job_name": "JOB2",
                "logical_operator": "EQUALS",
                "state": "SUCCEEDED"
              },
              {
                "crawl_state": "",
                "crawler_name": "",
                "job_name": "JOB3",
                "logical_operator": "EQUALS",
                "state": "SUCCEEDED"
              }
            ],
            "logical": "AND"
          }
        ],
        "schedule": "",
        "tags": {},
        "timeouts": {
          "create": null,
          "delete": null
        },
        "type": "CONDITIONAL",
        "workflow_name": "EXAMPLE_WORKFLOW"
      },
      "private": "some_private_string"
    }
  ]
}

According to docs predicate is defined as:-

predicate – (Optional) A predicate to specify when the new trigger should fire. Required when trigger type is CONDITIONAL. Defined below.

and args for predicate are defined as :-

conditions - (Required) A list of the conditions that determine when the trigger will fire. Defined below.

logical - (Optional) How to handle multiple conditions. Defaults to AND. Valid values are AND or ANY

Which matches the state output fine.

This is my latest iteration of trying to get this through the parser:-

resource "aws_glue_trigger" "EXAMPLE_TRIGGER" {
  name = "EXAMPLE_TRIGGER"
  type = "CONDITIONAL"
  workflow_name = "EXAMPLE_WORKFLOW"

  actions {
        arguments = {}
        crawler_name = "EXAMPLE_CRAWLER"
        job_name = ""
        timeout = 0
    }

  predicate {
    conditions = [{
        crawl_state = ""
        crawler_name = ""
        job_name = "JOB1"
        logical_operator = "EQUALS"
        state = "SUCCEEDED"
        },
        {
        crawl_state = ""
        crawler_name = ""
        job_name = "JOB2"
        logical_operator = "EQUALS"
        state = "SUCCEEDED"
        },
        {
        crawl_state = ""
        crawler_name = ""
        job_name = "JOB3"
        logical_operator = "EQUALS"
        state = "SUCCEEDED"
    }]
    logical = "AND"
    }
}

This is giving me an error "Error: Argument or block definition required" which implies it wants me to put an equals after conditions

An argument or block definition is required here. To set an argument, use the equals sign "=" to introduce the argument value.

This is contrary to the docs and examples at the doc page

When I add the equals I get "Error: Unsupported argument"

An argument named "conditions" is not expected here. Did you mean to define a block of type "conditions"?

Asking me to take the equals back out again and define as a block?

Im confused and probably missing something simple - but any help would be much appreciated.

1
Are you on Terraform 0.12? The plan output will show you the differences if you just create the minimal needed resource. I do this often when imported complex structures where I am not sure of all the requirements. - Andy Shinn
@andy-shinn Yeah - that is dead handy and what I'm trying to get to, but the syntax above won't parse to allow the plan to output. Thanks - 668NeighbourOfTheBeast
@Andy Sorry I get you now - reduced all the srgs to minimum and ran through plan which gives the syntax as required, rather than trying to brute force it first. Thanks a bunch - really appreciated :) Have edited with correct list syntax in case anyone else gets issues with this. - 668NeighbourOfTheBeast

1 Answers

2
votes

I have found the answer to this from Andy Shim's comment (once I had got it :) ) and it saved me here - Thank You. Only add the minimum args for the file to parse, then the plan output will give you all the syntax and inputs you need. For this one, to give a list of objects such as below, simply repeat the block:-

i.e dont do:-

conditions: [
          {
            "crawl_state": "",
            "crawler_name": "",
            "job_name": "JOB1",
            "logical_operator": "EQUALS",
            "state": "SUCCEEDED"
          },
          {
            "crawl_state": "",
            "crawler_name": "",
            "job_name": "JOB2",
            "logical_operator": "EQUALS",
            "state": "SUCCEEDED"
          },
          {
            "crawl_state": "",
            "crawler_name": "",
            "job_name": "JOB3",
            "logical_operator": "EQUALS",
            "state": "SUCCEEDED"
          }

but do:-

    conditions {
                "crawl_state": "",
                "crawler_name": "",
                "job_name": "JOB1",
                "logical_operator": "EQUALS",
                "state": "SUCCEEDED"
              }
   conditions {
                "crawl_state": "",
                "crawler_name": "",
                "job_name": "JOB2",
                "logical_operator": "EQUALS",
                "state": "SUCCEEDED"
              }
   conditions {
                "crawl_state": "",
                "crawler_name": "",
                "job_name": "JOB3",
                "logical_operator": "EQUALS",
                "state": "SUCCEEDED"
              }