Resource: aws_prometheus_scraper

Provides an Amazon Managed Service for Prometheus fully managed collector (scraper).

Read more in the Amazon Managed Service for Prometheus user guide.

Example Usage

Basic Usage

resource "aws_prometheus_scraper" "example" {
  source {
    eks {
      cluster_arn = data.aws_eks_cluster.example.arn
      subnet_ids  = data.aws_eks_cluster.example.vpc_config[0].subnet_ids
    }
  }

  destination {
    amp {
      workspace_arn = aws_prometheus_workspace.example.arn
    }
  }

  scrape_configuration = <<EOT
global:
  scrape_interval: 30s
scrape_configs:
  # pod metrics
  - job_name: pod_exporter
    kubernetes_sd_configs:
      - role: pod
  # container metrics
  - job_name: cadvisor
    scheme: https
    authorization:
      credentials_file: /var/run/secrets/kubernetes.io/serviceaccount/token
    kubernetes_sd_configs:
      - role: node
    relabel_configs:
      - action: labelmap
        regex: __meta_kubernetes_node_label_(.+)
      - replacement: kubernetes.default.svc:443
        target_label: __address__
      - source_labels: [__meta_kubernetes_node_name]
        regex: (.+)
        target_label: __metrics_path__
        replacement: /api/v1/nodes/$1/proxy/metrics/cadvisor
  # apiserver metrics
  - bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
    job_name: kubernetes-apiservers
    kubernetes_sd_configs:
    - role: endpoints
    relabel_configs:
    - action: keep
      regex: default;kubernetes;https
      source_labels:
      - __meta_kubernetes_namespace
      - __meta_kubernetes_service_name
      - __meta_kubernetes_endpoint_port_name
    scheme: https
  # kube proxy metrics
  - job_name: kube-proxy
    honor_labels: true
    kubernetes_sd_configs:
    - role: pod
    relabel_configs:
    - action: keep
      source_labels:
      - __meta_kubernetes_namespace
      - __meta_kubernetes_pod_name
      separator: '/'
      regex: 'kube-system/kube-proxy.+'
    - source_labels:
      - __address__
      action: replace
      target_label: __address__
      regex: (.+?)(\\:\\d+)?
      replacement: $1:10249
EOT
}

Ignoring changes to Prometheus Workspace destination

A managed scraper will add a AMPAgentlessScraper tag to its Prometheus workspace destination. To avoid Terraform state forcing removing the tag from the workspace, you can add this tag to the destination workspace (preferred) or ignore tags changes with lifecycle. See example below.

data "aws_eks_cluster" "this" {
  name = "example"
}

resource "aws_prometheus_workspace" "example" {
  tags = {
    AMPAgentlessScraper = ""
  }
}

resource "aws_prometheus_scraper" "example" {
  source {
    eks {
      cluster_arn = data.aws_eks_cluster.example.arn
      subnet_ids  = data.aws_eks_cluster.example.vpc_config[0].subnet_ids
    }
  }

  scrape_configuration = "..."

  destination {
    amp {
      workspace_arn = aws_prometheus_workspace.example.arn
    }
  }
}

Configure aws-auth

Your source Amazon EKS cluster must be configured to allow the scraper to access metrics. Follow the user guide to setup the appropriate Kubernetes permissions.

Argument Reference

The following arguments are required:

The following arguments are optional:

destination

amp

source

eks

Attribute Reference

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

Timeouts

Configuration options:

Import

In Terraform v1.5.0 and later, use an import block to import the Managed Scraper using the scraper identifier. For example:

import {
  to = aws_prometheus_scraper.example
  id = "s-0123abc-0000-0123-a000-000000000000"
}

Using terraform import, import the Managed Scraper using its identifier. For example:

% terraform import aws_prometheus_scraper.example s-0123abc-0000-0123-a000-000000000000