Este producto no es compatible con el sitio Datadog seleccionado. ().
Esta página aún no está disponible en español. Estamos trabajando en su traducción.
Si tienes alguna pregunta o comentario sobre nuestro actual proyecto de traducción, no dudes en ponerte en contacto con nosotros.

Metadata

Id: terraform-kubernetes-metadata-label-is-invalid

Provider: Kubernetes

Platform: Terraform

Severity: Low

Category: Best Practices

Learn More

Description

Checks whether any label in the resource metadata is invalid. The rule validates each label key against the regular expression ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$; when a label key does not match, the rule returns a result containing documentId, resourceType, resourceName, searchKey, issueType, keyExpectedValue, and keyActualValue. The issueType is IncorrectValue and searchKey points to the labels location (for example, <resourceType>[<name>].metadata.labels).

Compliant Code Examples

resource "kubernetes_pod" "test2" {
  metadata {
    name = "terraform-example"

    labels = {
      app = "MyApp"
    }
  }

  spec {
    container {
      image = "nginx:1.7.9"
      name  = "example"

      env {
        name  = "environment"
        value = "test"
      }

      port {
        container_port = 8080
      }

      liveness_probe {
        http_get {
          path = "/nginx_status"
          port = 80

          http_header {
            name  = "X-Custom-Header"
            value = "Awesome"
          }
        }

        initial_delay_seconds = 3
        period_seconds        = 3
      }
    }

    dns_config {
      nameservers = ["1.1.1.1", "8.8.8.8", "9.9.9.9"]
      searches    = ["example.com"]

      option {
        name  = "ndots"
        value = 1
      }

      option {
        name = "use-vc"
      }
    }

    dns_policy = "None"
  }
}
# Non-Kubernetes Terraform resources may use `metadata.labels` with values that
# do not satisfy the Kubernetes label-value regex. Those resources are governed
# by the schema of their own provider and should not be flagged by this rule.
resource "teleport_app" "bff_grpc" {
  version = "v3"
  metadata = {
    name = "bff-grpc-staging"
    labels = {
      environment           = "staging"
      app                   = "bff"
      transport             = "tcp"
      "teleport.dev/origin" = "dynamic"
    }
  }

  spec = {
    uri = "tcp://bff.example.com:443"
  }
}

Non-Compliant Code Examples

resource "kubernetes_pod" "test" {
  metadata {
    name = "terraform-example"

    labels = {
      app = "g**dy.l+bel"
    }
  }

  spec {
    container {
      image = "nginx:1.7.9"
      name  = "example"

      env {
        name  = "environment"
        value = "test"
      }

      port {
        container_port = 8080
      }

      liveness_probe {
        http_get {
          path = "/nginx_status"
          port = 80

          http_header {
            name  = "X-Custom-Header"
            value = "Awesome"
          }
        }

        initial_delay_seconds = 3
        period_seconds        = 3
      }
    }

    dns_config {
      nameservers = ["1.1.1.1", "8.8.8.8", "9.9.9.9"]
      searches    = ["example.com"]

      option {
        name  = "ndots"
        value = 1
      }

      option {
        name = "use-vc"
      }
    }

    dns_policy = "None"
  }
}