{
  "//": {
    "metadata": {
      "backend": "local",
      "stackName": "CloudCollectorV3Stack",
      "version": "0.23.3"
    },
    "outputs": {}
  },
  "data": {
    "aws_caller_identity": {
      "operata_aws_account_main_prod": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/operata_aws_account_main_prod",
            "uniqueId": "operata_aws_account_main_prod"
          }
        }
      }
    },
    "aws_iam_policy": {
      "operata_privacy_control_lambda_vpc_access_executionrole_policy_prod": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/operata_privacy_control_lambda_vpc_access_executionrole_policy_prod",
            "uniqueId": "operata_privacy_control_lambda_vpc_access_executionrole_policy_prod"
          }
        },
        "arn": "arn:${data.aws_partition.current.partition}:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
      }
    },
    "aws_iam_policy_document": {
      "operata_privacy_control_lambda_iam_assumerole_prod": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/operata_privacy_control_lambda_iam_assumerole_prod",
            "uniqueId": "operata_privacy_control_lambda_iam_assumerole_prod"
          }
        },
        "statement": [
          {
            "actions": [
              "sts:AssumeRole"
            ],
            "effect": "Allow",
            "principals": [
              {
                "identifiers": [
                  "lambda.amazonaws.com"
                ],
                "type": "Service"
              }
            ]
          }
        ]
      }
    },
    "aws_partition": {
      "current": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/current",
            "uniqueId": "current"
          }
        }
      }
    }
  },
  "provider": {
    "aws": [
      {
        "region": "${var.aws_region}"
      }
    ]
  },
  "resource": {
    "aws_cloudwatch_event_api_destination": {
      "operata_api_destination_prod": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/operata_api_destination_prod",
            "uniqueId": "operata_api_destination_prod"
          }
        },
        "connection_arn": "${aws_cloudwatch_event_connection.operata_connection_prod.arn}",
        "description": "API destination for sending CTR data to Operata for the${var.connect_instance_friendly_name}Amazon Connect instance",
        "http_method": "POST",
        "invocation_endpoint": "https://api.operata.io/v2/aws/events/contact-record",
        "name": "operata_endpoint_group_${var.operata_group_id}"
      }
    },
    "aws_cloudwatch_event_connection": {
      "operata_connection_prod": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/operata_connection_prod",
            "uniqueId": "operata_connection_prod"
          }
        },
        "auth_parameters": {
          "api_key": {
            "key": "Operata-API-Key",
            "value": "${aws_secretsmanager_secret_version.operata_api_key_secret_version_prod.secret_string}"
          },
          "invocation_http_parameters": {
            "header": [
              {
                "is_value_secret": false,
                "key": "Operata-Group-Id",
                "value": "${var.operata_group_id}"
              }
            ]
          }
        },
        "authorization_type": "API_KEY",
        "description": "EventBridge connection for transmitting CTR events to Operata for the ${var.connect_instance_friendly_name} Amazon Connect instance",
        "name": "operata_api_connection_prod"
      }
    },
    "aws_cloudwatch_log_group": {
      "operata_ctr_pipe_log_group_prod": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/operata_ctr_pipe_log_group_prod",
            "uniqueId": "operata_ctr_pipe_log_group_prod"
          }
        },
        "name": "/aws/pipes/operata_events_pipe_amazon_connect_${var.connect_instance_friendly_name}",
        "retention_in_days": 7
      }
    },
    "aws_iam_role": {
      "operata_event_bridge_pipe_role_prod": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/operata_event_bridge_pipe_role_prod",
            "uniqueId": "operata_event_bridge_pipe_role_prod"
          }
        },
        "assume_role_policy": "${jsonencode({\"Statement\" = [{\"Action\" = \"sts:AssumeRole\", \"Condition\" = {\"StringEquals\" = {\"aws:SourceAccount\" = data.aws_caller_identity.operata_aws_account_main_prod.account_id}}, \"Effect\" = \"Allow\", \"Principal\" = {\"Service\" = \"pipes.amazonaws.com\"}}], \"Version\" = \"2012-10-17\"})}"
      },
      "operata_privacy_control_lambda_iam_role_prod": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/operata_privacy_control_lambda_iam_role_prod",
            "uniqueId": "operata_privacy_control_lambda_iam_role_prod"
          }
        },
        "assume_role_policy": "${data.aws_iam_policy_document.operata_privacy_control_lambda_iam_assumerole_prod.json}",
        "inline_policy": [
          {
            "name": "operata_privacy_control_lambda_iam_policy_prod",
            "policy": "${jsonencode({\"Statement\" = [{\"Action\" = [\"ec2:DescribeNetworkInterfaces\", \"ec2:CreateNetworkInterface\", \"ec2:DeleteNetworkInterface\", \"ec2:DescribeInstances\", \"ec2:AttachNetworkInterface\"], \"Effect\" = \"Allow\", \"Resource\" = \"*\"}, {\"Action\" = [\"secretsmanager:GetSecretValue\"], \"Effect\" = \"Allow\", \"Resource\" = aws_secretsmanager_secret_version.operata_api_key_secret_version_prod.arn}, {\"Effect\" = \"Allow\", \"Action\" = [\"logs:CreateLogGroup\", \"logs:CreateLogStream\", \"logs:PutLogEvents\"], \"Resource\" = \"*\"}, {\"Action\" = [\"s3:GetObject\"], \"Effect\" = \"Allow\", \"Resource\" = \"arn:aws:s3:::${element(var.agent_data_s3_bucket_name, 0)}/*\"}, {\"Action\" = [\"s3:ListBucket\"], \"Effect\" = \"Allow\", \"Resource\" = \"arn:aws:s3:::${element(var.agent_data_s3_bucket_name, 0)}\"}], \"Version\" = \"2012-10-17\"})}"
          }
        ],
        "managed_policy_arns": [
          "${data.aws_iam_policy.operata_privacy_control_lambda_vpc_access_executionrole_policy_prod.arn}"
        ],
        "name": "operata_privacy_control_lambda_iam_role_prod"
      }
    },
    "aws_iam_role_policy": {
      "operata_ctr_pipe_logs_policy_prod": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/operata_ctr_pipe_logs_policy_prod",
            "uniqueId": "operata_ctr_pipe_logs_policy_prod"
          }
        },
        "name": "PipeLogsPolicy-Operata-CTR-GroupId-${var.operata_group_id}",
        "policy": "${jsonencode({\"Statement\" = [{\"Action\" = [\"logs:CreateLogStream\", \"logs:PutLogEvents\"], \"Effect\" = \"Allow\", \"Resource\" = aws_cloudwatch_log_group.operata_ctr_pipe_log_group_prod.arn}], \"Version\" = \"2012-10-17\"})}",
        "role": "${aws_iam_role.operata_event_bridge_pipe_role_prod.id}"
      },
      "operata_event_bridge_kinesis_pipe_sourcepolicy_prod": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/operata_event_bridge_kinesis_pipe_sourcepolicy_prod",
            "uniqueId": "operata_event_bridge_kinesis_pipe_sourcepolicy_prod"
          }
        },
        "name": "operata_kinesis_pipe_source_policy_prod",
        "policy": "${jsonencode({\"Statement\" = [{\"Action\" = [\"kinesis:DescribeStream\", \"kinesis:DescribeStreamSummary\", \"kinesis:GetRecords\", \"kinesis:GetShardIterator\", \"kinesis:ListStreams\", \"kinesis:ListShards\"], \"Effect\" = \"Allow\", \"Resource\" = [var.ctr_kinesis_stream_arn]}], \"Version\" = \"2012-10-17\"})}",
        "role": "${aws_iam_role.operata_event_bridge_pipe_role_prod.id}"
      },
      "operata_event_bridge_pipe_api_destination_policy_prod": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/operata_event_bridge_pipe_api_destination_policy_prod",
            "uniqueId": "operata_event_bridge_pipe_api_destination_policy_prod"
          }
        },
        "name": "operata_api_destination_policy_prod",
        "policy": "${jsonencode({\"Statement\" = [{\"Action\" = [\"events:InvokeApiDestination\"], \"Effect\" = \"Allow\", \"Resource\" = aws_cloudwatch_event_api_destination.operata_api_destination_prod.arn}], \"Version\" = \"2012-10-17\"})}",
        "role": "${aws_iam_role.operata_event_bridge_pipe_role_prod.id}"
      },
      "operata_event_bridge_pipe_lambda_policy_prod": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/operata_event_bridge_pipe_lambda_policy_prod",
            "uniqueId": "operata_event_bridge_pipe_lambda_policy_prod"
          }
        },
        "name": "operata_event_bridge_pipe_lambda_policy_prod",
        "policy": "${jsonencode({\"Statement\" = [{\"Action\" = [\"lambda:InvokeFunctionUrl\", \"lambda:InvokeFunction\"], \"Effect\" = \"Allow\", \"Resource\" = aws_lambda_function.operata_privacy_control_lambda_prod.arn}], \"Version\" = \"2012-10-17\"})}",
        "role": "${aws_iam_role.operata_event_bridge_pipe_role_prod.id}"
      }
    },
    "aws_lambda_function": {
      "operata_privacy_control_lambda_prod": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/operata_privacy_control_lambda_prod",
            "uniqueId": "operata_privacy_control_lambda_prod"
          }
        },
        "environment": {
          "variables": {
            "AGENT_DATA_S3_BUCKET": "${element(var.agent_data_s3_bucket_name, 0)}",
            "AGENT_DATA_S3_BUCKET_PREFIX": "${element(var.agent_data_s3_bucket_name, 1)}",
            "BUILD_VERSION": "v1.2.6",
            "LOG_LEVEL": "0",
            "OPERATA_API_KEY": "${aws_secretsmanager_secret_version.operata_api_key_secret_version_prod.arn}",
            "OPERATA_API_URL": "https://api.operata.io",
            "OPERATA_GROUP_ID": "${var.operata_group_id}"
          }
        },
        "function_name": "operata_privacy_control_lambda_prod",
        "handler": "bootstrap",
        "memory_size": 512,
        "role": "${aws_iam_role.operata_privacy_control_lambda_iam_role_prod.arn}",
        "runtime": "provided.al2023",
        "s3_bucket": "${var.aws_region}-operata-shared-assets-prod",
        "s3_key": "ccv3-lambdas/v1.2.6/cloud-collector-v3-contact-trace-records.zip",
        "timeout": 60,
        "vpc_config": {
          "security_group_ids": [
            "${aws_security_group.operata_privacy_control_lambda_security_group_prod.id}"
          ],
          "subnet_ids": "${var.enrichment_lambda_vpc_private_subnets}"
        }
      }
    },
    "aws_pipes_pipe": {
      "operata_events_pipe_prod": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/operata_events_pipe_prod",
            "uniqueId": "operata_events_pipe_prod"
          }
        },
        "description": "Pipe for sending CTR records to Operata (group ID: ${var.operata_group_id}) from the ${var.connect_instance_friendly_name} Amazon Connect instance in ${var.aws_region}",
        "enrichment": "${aws_lambda_function.operata_privacy_control_lambda_prod.arn}",
        "log_configuration": {
          "cloudwatch_logs_log_destination": {
            "log_group_arn": "${aws_cloudwatch_log_group.operata_ctr_pipe_log_group_prod.arn}"
          },
          "include_execution_data": [
            "ALL"
          ],
          "level": "ERROR"
        },
        "name": "operata_events_pipe_amazon_connect_${var.connect_instance_friendly_name}",
        "role_arn": "${aws_iam_role.operata_event_bridge_pipe_role_prod.arn}",
        "source": "${var.ctr_kinesis_stream_arn}",
        "source_parameters": {
          "filter_criteria": {
            "filter": [
              {
                "pattern": "${jsonencode({\"data\" = {\"Channel\" = [\"VOICE\"]}})}"
              }
            ]
          },
          "kinesis_stream_parameters": {
            "batch_size": 1,
            "maximum_record_age_in_seconds": -1,
            "maximum_retry_attempts": -1,
            "starting_position": "LATEST"
          }
        },
        "target": "${aws_cloudwatch_event_api_destination.operata_api_destination_prod.arn}"
      }
    },
    "aws_secretsmanager_secret": {
      "operata_api_key_secret_prod": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/operata_api_key_secret_prod",
            "uniqueId": "operata_api_key_secret_prod"
          }
        },
        "name": "/cloud-collector-v3/ctr/apiToken-prod"
      }
    },
    "aws_secretsmanager_secret_version": {
      "operata_api_key_secret_version_prod": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/operata_api_key_secret_version_prod",
            "uniqueId": "operata_api_key_secret_version_prod"
          }
        },
        "secret_id": "${aws_secretsmanager_secret.operata_api_key_secret_prod.id}",
        "secret_string": "${var.operata_api_key}"
      }
    },
    "aws_security_group": {
      "operata_privacy_control_lambda_security_group_prod": {
        "//": {
          "metadata": {
            "path": "CloudCollectorV3Stack/operata_privacy_control_lambda_security_group_prod",
            "uniqueId": "operata_privacy_control_lambda_security_group_prod"
          }
        },
        "description": "Security group for Operata Lambda Function - operata_privacy_control_lambda_prod",
        "egress": [
          {
            "cidr_blocks": [
              "0.0.0.0/0"
            ],
            "description": null,
            "from_port": 0,
            "ipv6_cidr_blocks": [
              "::/0"
            ],
            "prefix_list_ids": [],
            "protocol": "-1",
            "security_groups": [],
            "self": false,
            "to_port": 0
          }
        ],
        "vpc_id": "${var.enrichment_lambda_vpc_id}"
      }
    }
  },
  "terraform": {
    "backend": {
      "local": {
        "path": "terraform.CloudCollectorV3Stack.tfstate"
      }
    },
    "required_providers": {
      "aws": {
        "source": "aws",
        "version": "5.100.0"
      }
    }
  },
  "variable": {
    "agent_data_s3_bucket_name": {
      "description": "eg: [\"<bucket-name>\", \"<prefix>/\"] S3 bucket name where agent data is stored (optional)",
      "type": "list(string)"
    },
    "aws_region": {
      "description": "AWS Region where this stack will be created",
      "type": "string"
    },
    "connect_instance_friendly_name": {
      "description": "The friendly name of your Amazon Connect instance for ease of reference (i.e. Dev, Prod, UAT). Alphanumeric, no spaces.",
      "type": "string"
    },
    "ctr_kinesis_stream_arn": {
      "description": "The full ARN of the Kinesis Streams used by Amazon Connect for CTR records.",
      "type": "string"
    },
    "enrichment_lambda_vpc_id": {
      "description": "The VPC id where the enrichment lambda function will be deployed into",
      "type": "string"
    },
    "enrichment_lambda_vpc_private_subnets": {
      "description": "The private subnet ids where the enrichment lambda function will be deployed into (values should be comma seperated)",
      "type": "list(string)"
    },
    "operata_api_key": {
      "description": "API key generated in the Operata console",
      "sensitive": true,
      "type": "string"
    },
    "operata_group_id": {
      "description": "Operata Group ID provided by Operata",
      "type": "string"
    }
  }
}