Resource: aws_iot_topic_rule

Creates and manages an AWS IoT topic rule.

Example Usage

resource "aws_iot_topic_rule" "rule" {
  name        = "MyRule"
  description = "Example rule"
  enabled     = true
  sql         = "SELECT * FROM 'topic/test'"
  sql_version = "2016-03-23"

  sns {
    message_format = "RAW"
    role_arn       = aws_iam_role.role.arn
    target_arn     = aws_sns_topic.mytopic.arn
  }

  error_action {
    sns {
      message_format = "RAW"
      role_arn       = aws_iam_role.role.arn
      target_arn     = aws_sns_topic.myerrortopic.arn
    }
  }
}

resource "aws_sns_topic" "mytopic" {
  name = "mytopic"
}

resource "aws_sns_topic" "myerrortopic" {
  name = "myerrortopic"
}

data "aws_iam_policy_document" "assume_role" {
  statement {
    effect = "Allow"

    principals {
      type        = "Service"
      identifiers = ["iot.amazonaws.com"]
    }

    actions = ["sts:AssumeRole"]
  }
}

resource "aws_iam_role" "myrole" {
  name               = "myrole"
  assume_role_policy = data.aws_iam_policy_document.assume_role.json
}

data "aws_iam_policy_document" "mypolicy" {
  statement {
    effect    = "Allow"
    actions   = ["sns:Publish"]
    resources = [aws_sns_topic.mytopic.arn]
  }
}

resource "aws_iam_role_policy" "mypolicy" {
  name   = "mypolicy"
  role   = aws_iam_role.myrole.id
  policy = data.aws_iam_policy_document.mypolicy.json
}

Argument Reference

The cloudwatch_alarm object takes the following arguments:

The cloudwatch_logs object takes the following arguments:

The cloudwatch_metric object takes the following arguments:

The dynamodb object takes the following arguments:

The dynamodbv2 object takes the following arguments:

The elasticsearch object takes the following arguments:

The firehose object takes the following arguments:

The http object takes the following arguments:

The http_header object takes the following arguments:

The iot_analytics object takes the following arguments:

The iot_events object takes the following arguments:

The kafka object takes the following arguments:

The kinesis object takes the following arguments:

The lambda object takes the following arguments:

The republish object takes the following arguments:

The s3 object takes the following arguments:

The sns object takes the following arguments:

The sqs object takes the following arguments:

The step_functions object takes the following arguments:

The timestream object takes the following arguments:

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Import

In Terraform v1.5.0 and later, use an import block to import IoT Topic Rules using the name. For example:

import {
  to = aws_iot_topic_rule.rule
  id = "<name>"
}

Using terraform import, import IoT Topic Rules using the name. For example:

% terraform import aws_iot_topic_rule.rule <name>