How to specify topology keys for kubernetes service declared with terraform?

42 views Asked by At

I see that since 1.17 kubernetes has had alpha support for topology keys as a field on service definitions.

However, it seems that terraform does not allow specifying this key based on the docs found here.

I'm specifically using terraform cdk with typescript. How can I specify this key even though it's not yet officially supported by terraform?

I have the following

import { Service } from "@cdktf/provider-kubernetes/lib/service";

export class MyConstruct extends Construct {


  constructor(scope: Construct, name: string, config: MyConstruct) {
    super(scope, name);

    const selector = {
      app: "my-app",
      name,
    };


    new Service(this, "my-service", {
      metadata: {
        labels: {
          app: "my-app",
          name,
        },
        name,
      },
      spec: {
        port: [
          {
            // stuff
          },
        ],
        selector,
      },
    });
  }
}

But when I try to add a topologyKeys field as a sister of the Servic spec, typescript complains that Object literal may only specify known properties, and  topologyKeys  does not exist in type  ServiceSpec 

1

There are 1 answers

0
Paymahn Moghadasian On BEST ANSWER

Turns out I was using old docs and the way to turn this on is by adding an annotation to the service as explained here