Terraform Unsupported block error for selector in kubernetes_service resource

6/21/2019

Terraform configuration for heapster to deploy on kubernetes cluster is failing with error:

Blocks of type "selector" are not expected here. Did you mean to define
argument "selector"? If so, use the equals sign to assign it a value.

Resource configuration is:

resource "kubernetes_service" "service"{
    metadata {
        name="monitoring-influxdb"
        namespace="kube-system"
    }

    spec {
        selector {
            k8s-app="influxdb"
        }

        port{
            port=8086
            target_port=8086
        }
    }
}
-- Santosh Kumar
terraform
terraform-provider-kubernetes

2 Answers

7/16/2019

Had this same issue. Note the = and the error message If so, use the equals sign to assign it a value..

Simple fix:

selector = {
    k8s-app="influxdb"
}
-- Mike Bauer
Source: StackOverflow

6/24/2019

Your configuration file worked well with Terraform v0.11. Upon updating Terraform version and retrying it with version 0.12, it returned in the above error.

So this is a bug in Terraform v0.12

-- Mithilesh_Kunal
Source: StackOverflow