{
  "typeName" : "AWS::APS::Scraper",
  "description" : "Resource Type definition for AWS::APS::Scraper",
  "sourceUrl" : "https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-aps",
  "definitions" : {
    "Tag" : {
      "description" : "A key-value pair to associate with a resource.",
      "type" : "object",
      "properties" : {
        "Key" : {
          "type" : "string",
          "description" : "The key name of the tag. You can specify a value that is 1 to 128 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -.",
          "minLength" : 1,
          "maxLength" : 128
        },
        "Value" : {
          "type" : "string",
          "description" : "The value for the tag. You can specify a value that is 0 to 256 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -.",
          "minLength" : 0,
          "maxLength" : 256
        }
      },
      "required" : [ "Key", "Value" ],
      "additionalProperties" : false
    },
    "ScrapeConfiguration" : {
      "description" : "Scraper configuration",
      "type" : "object",
      "properties" : {
        "ConfigurationBlob" : {
          "description" : "Prometheus compatible scrape configuration in base64 encoded blob format",
          "type" : "string"
        }
      },
      "oneOf" : [ {
        "required" : [ "ConfigurationBlob" ]
      } ],
      "additionalProperties" : false
    },
    "RoleConfiguration" : {
      "description" : "Role configuration",
      "type" : "object",
      "properties" : {
        "SourceRoleArn" : {
          "description" : "IAM Role in source account",
          "type" : "string"
        },
        "TargetRoleArn" : {
          "description" : "IAM Role in the target account",
          "type" : "string"
        }
      },
      "additionalProperties" : false
    },
    "Source" : {
      "description" : "Scraper metrics source",
      "type" : "object",
      "properties" : {
        "EksConfiguration" : {
          "description" : "Configuration for EKS metrics source",
          "type" : "object",
          "properties" : {
            "ClusterArn" : {
              "description" : "ARN of an EKS cluster",
              "type" : "string",
              "pattern" : "^arn:aws[-a-z]*:eks:[-a-z0-9]+:[0-9]{12}:cluster/.+$"
            },
            "SecurityGroupIds" : {
              "description" : "List of security group IDs",
              "type" : "array",
              "insertionOrder" : false,
              "items" : {
                "$ref" : "#/definitions/SecurityGroupId"
              }
            },
            "SubnetIds" : {
              "description" : "List of subnet IDs",
              "type" : "array",
              "insertionOrder" : false,
              "items" : {
                "$ref" : "#/definitions/SubnetId"
              }
            }
          },
          "required" : [ "ClusterArn", "SubnetIds" ],
          "additionalProperties" : false
        },
        "VpcConfiguration" : {
          "description" : "Configuration for VPC metrics source",
          "type" : "object",
          "properties" : {
            "SecurityGroupIds" : {
              "description" : "List of security group IDs",
              "type" : "array",
              "insertionOrder" : false,
              "items" : {
                "$ref" : "#/definitions/SecurityGroupId"
              }
            },
            "SubnetIds" : {
              "description" : "List of subnet IDs",
              "type" : "array",
              "insertionOrder" : false,
              "items" : {
                "$ref" : "#/definitions/SubnetId"
              }
            }
          },
          "required" : [ "SecurityGroupIds", "SubnetIds" ],
          "additionalProperties" : false
        }
      },
      "oneOf" : [ {
        "required" : [ "EksConfiguration" ]
      }, {
        "required" : [ "VpcConfiguration" ]
      } ],
      "additionalProperties" : false
    },
    "Destination" : {
      "description" : "Scraper metrics destination",
      "type" : "object",
      "properties" : {
        "AmpConfiguration" : {
          "description" : "Configuration for Amazon Managed Prometheus metrics destination",
          "type" : "object",
          "properties" : {
            "WorkspaceArn" : {
              "description" : "ARN of an Amazon Managed Prometheus workspace",
              "type" : "string",
              "pattern" : "^arn:aws[-a-z]*:aps:[-a-z0-9]+:[0-9]{12}:workspace/.+$"
            }
          },
          "required" : [ "WorkspaceArn" ],
          "additionalProperties" : false
        }
      },
      "oneOf" : [ {
        "required" : [ "AmpConfiguration" ]
      } ],
      "additionalProperties" : false
    },
    "SecurityGroupId" : {
      "description" : "ID of a security group",
      "type" : "string",
      "pattern" : "^sg-[0-9a-z]+$"
    },
    "SubnetId" : {
      "description" : "ID of a subnet",
      "type" : "string",
      "pattern" : "^subnet-[0-9a-z]+$"
    },
    "CloudWatchLogDestination" : {
      "description" : "Represents a cloudwatch logs destination for scraper logging",
      "type" : "object",
      "properties" : {
        "LogGroupArn" : {
          "description" : "ARN of the CloudWatch log group",
          "type" : "string",
          "minLength" : 0,
          "maxLength" : 512
        }
      },
      "additionalProperties" : false
    },
    "ScraperComponentType" : {
      "type" : "string",
      "enum" : [ "SERVICE_DISCOVERY", "COLLECTOR", "EXPORTER" ],
      "description" : "Type of scraper component"
    },
    "ComponentConfig" : {
      "type" : "object",
      "properties" : {
        "Options" : {
          "type" : "object",
          "patternProperties" : {
            "^[A-Za-z0-9]+$" : {
              "type" : "string"
            }
          },
          "additionalProperties" : false
        }
      },
      "additionalProperties" : false
    },
    "ScraperComponent" : {
      "type" : "object",
      "properties" : {
        "Type" : {
          "$ref" : "#/definitions/ScraperComponentType"
        },
        "Config" : {
          "$ref" : "#/definitions/ComponentConfig"
        }
      },
      "required" : [ "Type" ],
      "additionalProperties" : false
    },
    "ScraperLoggingDestination" : {
      "description" : "Destination for scraper logging",
      "type" : "object",
      "properties" : {
        "CloudWatchLogs" : {
          "$ref" : "#/definitions/CloudWatchLogDestination"
        }
      },
      "additionalProperties" : false
    },
    "ScraperLoggingConfiguration" : {
      "description" : "Configuration for scraper logging",
      "type" : "object",
      "properties" : {
        "ScraperComponents" : {
          "type" : "array",
          "items" : {
            "$ref" : "#/definitions/ScraperComponent"
          },
          "minItems" : 1,
          "uniqueItems" : true
        },
        "LoggingDestination" : {
          "$ref" : "#/definitions/ScraperLoggingDestination"
        }
      },
      "required" : [ "ScraperComponents", "LoggingDestination" ],
      "additionalProperties" : false
    }
  },
  "properties" : {
    "ScraperId" : {
      "description" : "Required to identify a specific scraper.",
      "type" : "string",
      "pattern" : "^s-[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$",
      "minLength" : 1,
      "maxLength" : 64
    },
    "Alias" : {
      "description" : "Scraper alias.",
      "type" : "string",
      "pattern" : "^[0-9A-Za-z][-.0-9A-Z_a-z]*$",
      "minLength" : 1,
      "maxLength" : 100
    },
    "Arn" : {
      "description" : "Scraper ARN.",
      "type" : "string",
      "pattern" : "^arn:(aws|aws-us-gov|aws-cn):aps:[a-z0-9-]+:[0-9]+:scraper/s-[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$"
    },
    "RoleArn" : {
      "description" : "IAM role ARN for the scraper.",
      "type" : "string",
      "pattern" : "^arn:(aws|aws-us-gov|aws-cn):iam::[0-9]{12}:role/[a-zA-Z0-9-]+$",
      "minLength" : 20,
      "maxLength" : 2048
    },
    "ScraperLoggingConfiguration" : {
      "$ref" : "#/definitions/ScraperLoggingConfiguration"
    },
    "ScrapeConfiguration" : {
      "$ref" : "#/definitions/ScrapeConfiguration"
    },
    "RoleConfiguration" : {
      "$ref" : "#/definitions/RoleConfiguration"
    },
    "Source" : {
      "$ref" : "#/definitions/Source"
    },
    "Destination" : {
      "$ref" : "#/definitions/Destination"
    },
    "Tags" : {
      "description" : "An array of key-value pairs to apply to this resource.",
      "type" : "array",
      "uniqueItems" : true,
      "insertionOrder" : false,
      "items" : {
        "$ref" : "#/definitions/Tag"
      }
    }
  },
  "additionalProperties" : false,
  "required" : [ "ScrapeConfiguration", "Source", "Destination" ],
  "readOnlyProperties" : [ "/properties/ScraperId", "/properties/Arn", "/properties/RoleArn" ],
  "createOnlyProperties" : [ "/properties/Source" ],
  "tagging" : {
    "taggable" : true,
    "tagOnCreate" : true,
    "tagUpdatable" : true,
    "cloudFormationSystemTags" : true,
    "tagProperty" : "/properties/Tags",
    "permissions" : [ "aps:TagResource", "aps:UntagResource" ]
  },
  "primaryIdentifier" : [ "/properties/Arn" ],
  "handlers" : {
    "create" : {
      "permissions" : [ "aps:CreateScraper", "aps:UpdateScraperLoggingConfiguration", "aps:DescribeScraper", "aps:DescribeWorkspace", "aps:TagResource", "eks:CreateAccessEntry", "eks:AssociateAccessPolicy", "eks:DescribeCluster", "ec2:DescribeSubnets", "ec2:DescribeSecurityGroups", "ec2:DescribeNetworkInterfaces", "ec2:CreateNetworkInterface", "ec2:DeleteNetworkInterface", "ec2:AttachNetworkInterface", "ec2:DetachNetworkInterface", "ec2:ModifyNetworkInterfaceAttribute", "ec2:DescribeVpcs", "kafka:DescribeCluster", "kafka:DescribeClusterV2", "kafka:GetBootstrapBrokers", "kafka:ListClusters", "kafka:ListNodes", "iam:CreateServiceLinkedRole", "iam:PassRole", "logs:CreateLogDelivery", "logs:GetLogDelivery", "logs:ListLogDeliveries", "logs:PutResourcePolicy", "logs:DescribeLogGroups" ]
    },
    "read" : {
      "permissions" : [ "aps:DescribeScraper", "aps:DescribeScraperLoggingConfiguration", "aps:ListTagsForResource", "ec2:DescribeNetworkInterfaces" ]
    },
    "update" : {
      "permissions" : [ "aps:CreateScraper", "aps:DescribeScraper", "aps:UpdateScraper", "aps:DescribeWorkspace", "aps:DescribeScraperLoggingConfiguration", "aps:DeleteScraperLoggingConfiguration", "aps:UpdateScraperLoggingConfiguration", "aps:TagResource", "aps:UntagResource", "aps:ListTagsForResource", "ec2:DescribeSubnets", "ec2:DescribeSecurityGroups", "ec2:DescribeNetworkInterfaces", "ec2:ModifyNetworkInterfaceAttribute", "ec2:DescribeVpcs", "kafka:DescribeCluster", "kafka:DescribeClusterV2", "kafka:GetBootstrapBrokers", "iam:PassRole", "logs:CreateLogDelivery", "logs:GetLogDelivery", "logs:UpdateLogDelivery", "logs:ListLogDeliveries", "logs:PutResourcePolicy", "logs:DescribeLogGroups" ]
    },
    "delete" : {
      "permissions" : [ "aps:DeleteScraper", "aps:DescribeScraper", "aps:DescribeWorkspace", "aps:DeleteScraperLoggingConfiguration", "eks:AssociateAccessPolicy", "eks:DescribeCluster", "ec2:DescribeSubnets", "ec2:DescribeSecurityGroups", "ec2:DescribeNetworkInterfaces", "ec2:DeleteNetworkInterface", "ec2:DetachNetworkInterface", "ec2:DescribeVpcs", "kafka:DescribeCluster", "iam:DeleteServiceLinkedRole", "logs:DeleteLogDelivery" ]
    },
    "list" : {
      "permissions" : [ "aps:ListScrapers", "aps:ListTagsForResource" ]
    }
  }
}