# coding=utf-8
# *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. ***
# *** Do not edit by hand unless you're certain you know what you are doing! ***

import json
import warnings
import pulumi
import pulumi.runtime
from typing import Union
from .. import utilities, tables

class TopicRule(pulumi.CustomResource):
    arn: pulumi.Output[str]
    """
    The ARN of the topic rule
    """
    cloudwatch_alarm: pulumi.Output[dict]
    cloudwatch_metric: pulumi.Output[dict]
    description: pulumi.Output[str]
    """
    The description of the rule.
    """
    dynamodb: pulumi.Output[dict]
    dynamodbv2s: pulumi.Output[list]
    elasticsearch: pulumi.Output[dict]
    enabled: pulumi.Output[bool]
    """
    Specifies whether the rule is enabled.
    """
    firehose: pulumi.Output[dict]
    iot_analytics: pulumi.Output[list]
    iot_events: pulumi.Output[list]
    kinesis: pulumi.Output[dict]
    lambda_: pulumi.Output[dict]
    name: pulumi.Output[str]
    """
    The name of the rule.
    """
    republish: pulumi.Output[dict]
    s3: pulumi.Output[dict]
    sns: pulumi.Output[dict]
    sql: pulumi.Output[str]
    """
    The SQL statement used to query the topic. For more information, see AWS IoT SQL Reference (http://docs.aws.amazon.com/iot/latest/developerguide/iot-rules.html#aws-iot-sql-reference) in the AWS IoT Developer Guide.
    """
    sql_version: pulumi.Output[str]
    """
    The version of the SQL rules engine to use when evaluating the rule.
    """
    sqs: pulumi.Output[dict]
    def __init__(__self__, resource_name, opts=None, cloudwatch_alarm=None, cloudwatch_metric=None, description=None, dynamodb=None, dynamodbv2s=None, elasticsearch=None, enabled=None, firehose=None, iot_analytics=None, iot_events=None, kinesis=None, lambda_=None, name=None, republish=None, s3=None, sns=None, sql=None, sql_version=None, sqs=None, __props__=None, __name__=None, __opts__=None):
        """
        ## Example Usage



        ```python
        import pulumi
        import pulumi_aws as aws

        mytopic = aws.sns.Topic("mytopic")
        role = aws.iam.Role("role", assume_role_policy=\"\"\"{
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Principal": {
                "Service": "iot.amazonaws.com"
              },
              "Action": "sts:AssumeRole"
            }
          ]
        }

        \"\"\")
        rule = aws.iot.TopicRule("rule",
            description="Example rule",
            enabled=True,
            sns={
                "sns": "RAW",
                "sns": role.arn,
                "sns": mytopic.arn,
            },
            sql="SELECT * FROM 'topic/test'",
            sql_version="2016-03-23")
        iam_policy_for_lambda = aws.iam.RolePolicy("iamPolicyForLambda",
            policy=mytopic.arn.apply(lambda arn: f\"\"\"{{
          "Version": "2012-10-17",
          "Statement": [
            {{
                "Effect": "Allow",
                "Action": [
                    "sns:Publish"
                ],
                "Resource": "{arn}"
            }}
          ]
        }}

        \"\"\"),
            role=role.id)
        ```


        :param str resource_name: The name of the resource.
        :param pulumi.ResourceOptions opts: Options for the resource.
        :param pulumi.Input[str] description: The description of the rule.
        :param pulumi.Input[bool] enabled: Specifies whether the rule is enabled.
        :param pulumi.Input[str] name: The name of the rule.
        :param pulumi.Input[str] sql: The SQL statement used to query the topic. For more information, see AWS IoT SQL Reference (http://docs.aws.amazon.com/iot/latest/developerguide/iot-rules.html#aws-iot-sql-reference) in the AWS IoT Developer Guide.
        :param pulumi.Input[str] sql_version: The version of the SQL rules engine to use when evaluating the rule.

        The **cloudwatch_alarm** object supports the following:

          * `alarmName` (`pulumi.Input[str]`) - The CloudWatch alarm name.
          * `role_arn` (`pulumi.Input[str]`) - The IAM role ARN that allows access to the CloudWatch alarm.
          * `stateReason` (`pulumi.Input[str]`) - The reason for the alarm change.
          * `stateValue` (`pulumi.Input[str]`) - The value of the alarm state. Acceptable values are: OK, ALARM, INSUFFICIENT_DATA.

        The **cloudwatch_metric** object supports the following:

          * `metric_name` (`pulumi.Input[str]`) - The CloudWatch metric name.
          * `metricNamespace` (`pulumi.Input[str]`) - The CloudWatch metric namespace name.
          * `metricTimestamp` (`pulumi.Input[str]`) - An optional Unix timestamp (http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/cloudwatch_concepts.html#about_timestamp).
          * `metricUnit` (`pulumi.Input[str]`) - The metric unit (supported units can be found here: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/cloudwatch_concepts.html#Unit)
          * `metricValue` (`pulumi.Input[str]`) - The CloudWatch metric value.
          * `role_arn` (`pulumi.Input[str]`) - The IAM role ARN that allows access to the CloudWatch metric.

        The **dynamodb** object supports the following:

          * `hashKeyField` (`pulumi.Input[str]`) - The hash key name.
          * `hashKeyType` (`pulumi.Input[str]`) - The hash key type. Valid values are "STRING" or "NUMBER".
          * `hashKeyValue` (`pulumi.Input[str]`) - The hash key value.
          * `operation` (`pulumi.Input[str]`) - The operation. Valid values are "INSERT", "UPDATE", or "DELETE".
          * `payloadField` (`pulumi.Input[str]`) - The action payload.
          * `rangeKeyField` (`pulumi.Input[str]`) - The range key name.
          * `rangeKeyType` (`pulumi.Input[str]`) - The range key type. Valid values are "STRING" or "NUMBER".
          * `rangeKeyValue` (`pulumi.Input[str]`) - The range key value.
          * `role_arn` (`pulumi.Input[str]`) - The ARN of the IAM role that grants access to the DynamoDB table.
          * `table_name` (`pulumi.Input[str]`) - The name of the DynamoDB table.

        The **dynamodbv2s** object supports the following:

          * `putItem` (`pulumi.Input[dict]`) - Configuration block with DynamoDB Table to which the message will be written. Nested arguments below.
            * `table_name` (`pulumi.Input[str]`) - The name of the DynamoDB table.

          * `role_arn` (`pulumi.Input[str]`) - The IAM role ARN that allows access to the CloudWatch alarm.

        The **elasticsearch** object supports the following:

          * `endpoint` (`pulumi.Input[str]`) - The endpoint of your Elasticsearch domain.
          * `id` (`pulumi.Input[str]`) - The unique identifier for the document you are storing.
          * `index` (`pulumi.Input[str]`) - The Elasticsearch index where you want to store your data.
          * `role_arn` (`pulumi.Input[str]`) - The IAM role ARN that has access to Elasticsearch.
          * `type` (`pulumi.Input[str]`) - The type of document you are storing.

        The **firehose** object supports the following:

          * `deliveryStreamName` (`pulumi.Input[str]`) - The delivery stream name.
          * `role_arn` (`pulumi.Input[str]`) - The IAM role ARN that grants access to the Amazon Kinesis Firehose stream.
          * `separator` (`pulumi.Input[str]`) - A character separator that is used to separate records written to the Firehose stream. Valid values are: '\n' (newline), '\t' (tab), '\r\n' (Windows newline), ',' (comma).

        The **iot_analytics** object supports the following:

          * `channelName` (`pulumi.Input[str]`) - Name of AWS IOT Analytics channel.
          * `role_arn` (`pulumi.Input[str]`) - The ARN of the IAM role that grants access.

        The **iot_events** object supports the following:

          * `inputName` (`pulumi.Input[str]`) - The name of the AWS IoT Events input.
          * `messageId` (`pulumi.Input[str]`) - Use this to ensure that only one input (message) with a given messageId is processed by an AWS IoT Events detector. 
          * `role_arn` (`pulumi.Input[str]`) - The ARN of the IAM role that grants access.

        The **kinesis** object supports the following:

          * `partitionKey` (`pulumi.Input[str]`) - The partition key.
          * `role_arn` (`pulumi.Input[str]`) - The ARN of the IAM role that grants access to the Amazon Kinesis stream.
          * `streamName` (`pulumi.Input[str]`) - The name of the Amazon Kinesis stream.

        The **lambda_** object supports the following:

          * `function_arn` (`pulumi.Input[str]`) - The ARN of the Lambda function.

        The **republish** object supports the following:

          * `qos` (`pulumi.Input[float]`) - The Quality of Service (QoS) level to use when republishing messages. Valid values are 0 or 1. The default value is 0. 
          * `role_arn` (`pulumi.Input[str]`) - The ARN of the IAM role that grants access.
          * `topic` (`pulumi.Input[str]`) - The name of the MQTT topic the message should be republished to.

        The **s3** object supports the following:

          * `bucket_name` (`pulumi.Input[str]`) - The Amazon S3 bucket name.
          * `key` (`pulumi.Input[str]`) - The object key.
          * `role_arn` (`pulumi.Input[str]`) - The IAM role ARN that allows access to the CloudWatch alarm.

        The **sns** object supports the following:

          * `messageFormat` (`pulumi.Input[str]`) - The message format of the message to publish. Accepted values are "JSON" and "RAW".
          * `role_arn` (`pulumi.Input[str]`) - The ARN of the IAM role that grants access.
          * `target_arn` (`pulumi.Input[str]`) - The ARN of the SNS topic.

        The **sqs** object supports the following:

          * `queue_url` (`pulumi.Input[str]`) - The URL of the Amazon SQS queue.
          * `role_arn` (`pulumi.Input[str]`) - The ARN of the IAM role that grants access.
          * `useBase64` (`pulumi.Input[bool]`) - Specifies whether to use Base64 encoding.
        """
        if __name__ is not None:
            warnings.warn("explicit use of __name__ is deprecated", DeprecationWarning)
            resource_name = __name__
        if __opts__ is not None:
            warnings.warn("explicit use of __opts__ is deprecated, use 'opts' instead", DeprecationWarning)
            opts = __opts__
        if opts is None:
            opts = pulumi.ResourceOptions()
        if not isinstance(opts, pulumi.ResourceOptions):
            raise TypeError('Expected resource options to be a ResourceOptions instance')
        if opts.version is None:
            opts.version = utilities.get_version()
        if opts.id is None:
            if __props__ is not None:
                raise TypeError('__props__ is only valid when passed in combination with a valid opts.id to get an existing resource')
            __props__ = dict()

            __props__['cloudwatch_alarm'] = cloudwatch_alarm
            __props__['cloudwatch_metric'] = cloudwatch_metric
            __props__['description'] = description
            __props__['dynamodb'] = dynamodb
            __props__['dynamodbv2s'] = dynamodbv2s
            __props__['elasticsearch'] = elasticsearch
            if enabled is None:
                raise TypeError("Missing required property 'enabled'")
            __props__['enabled'] = enabled
            __props__['firehose'] = firehose
            __props__['iot_analytics'] = iot_analytics
            __props__['iot_events'] = iot_events
            __props__['kinesis'] = kinesis
            __props__['lambda_'] = lambda_
            __props__['name'] = name
            __props__['republish'] = republish
            __props__['s3'] = s3
            __props__['sns'] = sns
            if sql is None:
                raise TypeError("Missing required property 'sql'")
            __props__['sql'] = sql
            if sql_version is None:
                raise TypeError("Missing required property 'sql_version'")
            __props__['sql_version'] = sql_version
            __props__['sqs'] = sqs
            __props__['arn'] = None
        super(TopicRule, __self__).__init__(
            'aws:iot/topicRule:TopicRule',
            resource_name,
            __props__,
            opts)

    @staticmethod
    def get(resource_name, id, opts=None, arn=None, cloudwatch_alarm=None, cloudwatch_metric=None, description=None, dynamodb=None, dynamodbv2s=None, elasticsearch=None, enabled=None, firehose=None, iot_analytics=None, iot_events=None, kinesis=None, lambda_=None, name=None, republish=None, s3=None, sns=None, sql=None, sql_version=None, sqs=None):
        """
        Get an existing TopicRule resource's state with the given name, id, and optional extra
        properties used to qualify the lookup.

        :param str resource_name: The unique name of the resulting resource.
        :param str id: The unique provider ID of the resource to lookup.
        :param pulumi.ResourceOptions opts: Options for the resource.
        :param pulumi.Input[str] arn: The ARN of the topic rule
        :param pulumi.Input[str] description: The description of the rule.
        :param pulumi.Input[bool] enabled: Specifies whether the rule is enabled.
        :param pulumi.Input[str] name: The name of the rule.
        :param pulumi.Input[str] sql: The SQL statement used to query the topic. For more information, see AWS IoT SQL Reference (http://docs.aws.amazon.com/iot/latest/developerguide/iot-rules.html#aws-iot-sql-reference) in the AWS IoT Developer Guide.
        :param pulumi.Input[str] sql_version: The version of the SQL rules engine to use when evaluating the rule.

        The **cloudwatch_alarm** object supports the following:

          * `alarmName` (`pulumi.Input[str]`) - The CloudWatch alarm name.
          * `role_arn` (`pulumi.Input[str]`) - The IAM role ARN that allows access to the CloudWatch alarm.
          * `stateReason` (`pulumi.Input[str]`) - The reason for the alarm change.
          * `stateValue` (`pulumi.Input[str]`) - The value of the alarm state. Acceptable values are: OK, ALARM, INSUFFICIENT_DATA.

        The **cloudwatch_metric** object supports the following:

          * `metric_name` (`pulumi.Input[str]`) - The CloudWatch metric name.
          * `metricNamespace` (`pulumi.Input[str]`) - The CloudWatch metric namespace name.
          * `metricTimestamp` (`pulumi.Input[str]`) - An optional Unix timestamp (http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/cloudwatch_concepts.html#about_timestamp).
          * `metricUnit` (`pulumi.Input[str]`) - The metric unit (supported units can be found here: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/cloudwatch_concepts.html#Unit)
          * `metricValue` (`pulumi.Input[str]`) - The CloudWatch metric value.
          * `role_arn` (`pulumi.Input[str]`) - The IAM role ARN that allows access to the CloudWatch metric.

        The **dynamodb** object supports the following:

          * `hashKeyField` (`pulumi.Input[str]`) - The hash key name.
          * `hashKeyType` (`pulumi.Input[str]`) - The hash key type. Valid values are "STRING" or "NUMBER".
          * `hashKeyValue` (`pulumi.Input[str]`) - The hash key value.
          * `operation` (`pulumi.Input[str]`) - The operation. Valid values are "INSERT", "UPDATE", or "DELETE".
          * `payloadField` (`pulumi.Input[str]`) - The action payload.
          * `rangeKeyField` (`pulumi.Input[str]`) - The range key name.
          * `rangeKeyType` (`pulumi.Input[str]`) - The range key type. Valid values are "STRING" or "NUMBER".
          * `rangeKeyValue` (`pulumi.Input[str]`) - The range key value.
          * `role_arn` (`pulumi.Input[str]`) - The ARN of the IAM role that grants access to the DynamoDB table.
          * `table_name` (`pulumi.Input[str]`) - The name of the DynamoDB table.

        The **dynamodbv2s** object supports the following:

          * `putItem` (`pulumi.Input[dict]`) - Configuration block with DynamoDB Table to which the message will be written. Nested arguments below.
            * `table_name` (`pulumi.Input[str]`) - The name of the DynamoDB table.

          * `role_arn` (`pulumi.Input[str]`) - The IAM role ARN that allows access to the CloudWatch alarm.

        The **elasticsearch** object supports the following:

          * `endpoint` (`pulumi.Input[str]`) - The endpoint of your Elasticsearch domain.
          * `id` (`pulumi.Input[str]`) - The unique identifier for the document you are storing.
          * `index` (`pulumi.Input[str]`) - The Elasticsearch index where you want to store your data.
          * `role_arn` (`pulumi.Input[str]`) - The IAM role ARN that has access to Elasticsearch.
          * `type` (`pulumi.Input[str]`) - The type of document you are storing.

        The **firehose** object supports the following:

          * `deliveryStreamName` (`pulumi.Input[str]`) - The delivery stream name.
          * `role_arn` (`pulumi.Input[str]`) - The IAM role ARN that grants access to the Amazon Kinesis Firehose stream.
          * `separator` (`pulumi.Input[str]`) - A character separator that is used to separate records written to the Firehose stream. Valid values are: '\n' (newline), '\t' (tab), '\r\n' (Windows newline), ',' (comma).

        The **iot_analytics** object supports the following:

          * `channelName` (`pulumi.Input[str]`) - Name of AWS IOT Analytics channel.
          * `role_arn` (`pulumi.Input[str]`) - The ARN of the IAM role that grants access.

        The **iot_events** object supports the following:

          * `inputName` (`pulumi.Input[str]`) - The name of the AWS IoT Events input.
          * `messageId` (`pulumi.Input[str]`) - Use this to ensure that only one input (message) with a given messageId is processed by an AWS IoT Events detector. 
          * `role_arn` (`pulumi.Input[str]`) - The ARN of the IAM role that grants access.

        The **kinesis** object supports the following:

          * `partitionKey` (`pulumi.Input[str]`) - The partition key.
          * `role_arn` (`pulumi.Input[str]`) - The ARN of the IAM role that grants access to the Amazon Kinesis stream.
          * `streamName` (`pulumi.Input[str]`) - The name of the Amazon Kinesis stream.

        The **lambda_** object supports the following:

          * `function_arn` (`pulumi.Input[str]`) - The ARN of the Lambda function.

        The **republish** object supports the following:

          * `qos` (`pulumi.Input[float]`) - The Quality of Service (QoS) level to use when republishing messages. Valid values are 0 or 1. The default value is 0. 
          * `role_arn` (`pulumi.Input[str]`) - The ARN of the IAM role that grants access.
          * `topic` (`pulumi.Input[str]`) - The name of the MQTT topic the message should be republished to.

        The **s3** object supports the following:

          * `bucket_name` (`pulumi.Input[str]`) - The Amazon S3 bucket name.
          * `key` (`pulumi.Input[str]`) - The object key.
          * `role_arn` (`pulumi.Input[str]`) - The IAM role ARN that allows access to the CloudWatch alarm.

        The **sns** object supports the following:

          * `messageFormat` (`pulumi.Input[str]`) - The message format of the message to publish. Accepted values are "JSON" and "RAW".
          * `role_arn` (`pulumi.Input[str]`) - The ARN of the IAM role that grants access.
          * `target_arn` (`pulumi.Input[str]`) - The ARN of the SNS topic.

        The **sqs** object supports the following:

          * `queue_url` (`pulumi.Input[str]`) - The URL of the Amazon SQS queue.
          * `role_arn` (`pulumi.Input[str]`) - The ARN of the IAM role that grants access.
          * `useBase64` (`pulumi.Input[bool]`) - Specifies whether to use Base64 encoding.
        """
        opts = pulumi.ResourceOptions.merge(opts, pulumi.ResourceOptions(id=id))

        __props__ = dict()

        __props__["arn"] = arn
        __props__["cloudwatch_alarm"] = cloudwatch_alarm
        __props__["cloudwatch_metric"] = cloudwatch_metric
        __props__["description"] = description
        __props__["dynamodb"] = dynamodb
        __props__["dynamodbv2s"] = dynamodbv2s
        __props__["elasticsearch"] = elasticsearch
        __props__["enabled"] = enabled
        __props__["firehose"] = firehose
        __props__["iot_analytics"] = iot_analytics
        __props__["iot_events"] = iot_events
        __props__["kinesis"] = kinesis
        __props__["lambda_"] = lambda_
        __props__["name"] = name
        __props__["republish"] = republish
        __props__["s3"] = s3
        __props__["sns"] = sns
        __props__["sql"] = sql
        __props__["sql_version"] = sql_version
        __props__["sqs"] = sqs
        return TopicRule(resource_name, opts=opts, __props__=__props__)
    def translate_output_property(self, prop):
        return tables._CAMEL_TO_SNAKE_CASE_TABLE.get(prop) or prop

    def translate_input_property(self, prop):
        return tables._SNAKE_TO_CAMEL_CASE_TABLE.get(prop) or prop

