3

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
  • 761
  • 5
  • 28
  • What is your terraform version? – Mithilesh_Kunal Jun 21 '19 at 04:13
  • Terraform v0.12.2 + provider.kubernetes v1.7.0 – Santosh Kumar Jun 21 '19 at 04:42
  • `terraform plan` didn't give me any error. – Mithilesh_Kunal Jun 21 '19 at 05:43
  • @Mithilesh_Kunal - Are you also using same versions. I tried same config on a new VM again, but it's failing with same error: `Error: Unsupported block type on main.tf line 24, in resource "kubernetes_service" "example": 24: selector { 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.` – Santosh Kumar Jun 21 '19 at 06:17
  • 2
    It worked on terraform v0.11. I updated the terraform version to v0.12 and it failed with the same error as yours. There is an error with this version. Please downgrade to v0.11 or raise an issue with terraform github. – Mithilesh_Kunal Jun 21 '19 at 06:42
  • @Mithilesh_Kunal You should provide that as an answer, especially because intuition would probably lead people to think the provider is at fault here. – Matthew Schuchard Jun 21 '19 at 14:22
  • Added the above comment as an answer. Thanks – Mithilesh_Kunal Jun 25 '19 at 03:14

2 Answers2

3

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
  • 31
  • 1
2

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
  • 873
  • 7
  • 12
  • This is not a bug, it's just stricter syntax checking in 0.12, see Mike Bauer's answer. "selector" is a map so now needs the "=" before the block. – Nick Wilson Jan 02 '20 at 12:19