Search code examples
amazon-web-servicesterraformterraform-provider-awsaws-iot-core

Using topic function in republish topic aws iot core from terraform


I try to create iot rule like this using terraform module https://github.com/QuiNovas/terraform-aws-iot-topic-rule

module "iot_rule_2" {
  name = "xxx"
  sql_query = "xxx"
  source = "QuiNovas/iot-topic-rule/aws"
  version = "1.0.4"
  republish = [{topic = "$$aws/things/${topic(3)}/shadow/name/datamodel/update"}]
}

and I get the error

Error: Call to unknown function
│
│   on main.tf line 52, in module "iot_rule_2":
│   52:   republish = [{topic = "$$aws/things/${topic(3)}/shadow/name/datamodel/update"}]
│
│ There is no function named "topic".

The topic function exists in AWS https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-functions.html


Solution

  • Ok, I found the solution - we should prefix with additional $.

    module "iot_rule_2" {
      name = "xxx"
      sql_query = "xxx"
      source = "QuiNovas/iot-topic-rule/aws"
      version = "1.0.4"
      republish = [{topic = "$$aws/things/$${topic(3)}/shadow/name/datamodel/update"}]
    }