Hello Everyone, I've stuck working with Pulumi In...
# general
b
Hello Everyone, I've stuck working with Pulumi Input. Can't make it through. If someone has time, please check my attached screenshot in the thread.
Copy code
let x = new k8s.core.v1.Service(
            "test-service-lb",
            {
                metadata: {
                    name: "test-service-lb",
                    namespace: "default",
                    labels: {
                        "test-service": "test-service-lb"
                    },
                    annotations: {
                        "<http://service.beta.kubernetes.io/aws-load-balancer-type|service.beta.kubernetes.io/aws-load-balancer-type>": "nlb",
                        "<http://service.beta.kubernetes.io/aws-load-balancer-internal|service.beta.kubernetes.io/aws-load-balancer-internal>": "true",
                        "<http://service.beta.kubernetes.io/aws-load-balancer-backend-protocol|service.beta.kubernetes.io/aws-load-balancer-backend-protocol>": "http",
                        "<http://pulumi.com/skipAwait|pulumi.com/skipAwait>": "true"
                    }
                },
                spec: {
                    type: "LoadBalancer",
                    ports: [{
                        port: 80,
                        targetPort: 9090,
                        protocol: "TCP"
                    }],
                    selector: {
                        "app": "prometheus-operator-prometheus"
                    },
                    loadBalancerSourceRanges: [
                        "10.0.0.0/8",
                        (() => {
                            <http://pulumi.log.info|pulumi.log.info>("The cluster name is " + this.args.name)
                            if (`${this.args.name}`.toLowerCase().endsWith("-prod")) {
                                <http://pulumi.log.info|pulumi.log.info>("Subnet was not added")
                                return undefined
                            } else {
                                <http://pulumi.log.info|pulumi.log.info>("Added the subnet")
                                return "100.72.0.0/16"
                            }
                        })()
                    ]
                },
            },
            {
                provider: this.asfEksCluster.provider
            }
        )
a
It looks to me like the problem is where you
return undefined
.
b
^. It wants a string and your function returns string OR undefined.
a
I think what you would want to do instead is something like this:
Copy code
const loadBalancerSourceRanges = ['10.0.0.0/8']
<http://pulumi.log.info|pulumi.log.info>("The cluster name is " + this.args.name)
if (`${this.args.name}`.toLowerCase().endsWith("-prod")) {
  <http://pulumi.log.info|pulumi.log.info>("Subnet was not added")
} else {
  <http://pulumi.log.info|pulumi.log.info>("Added the subnet")
  loadBalancerSourceRanges.push("100.72.0.0/16")
}

let x = new k8s.core.v1.Service(
  "test-service-lb",
  ...
  spec: {
    ...
    loadBalancerSourceRanges: loadBalancerSourceRanges
    ...
  }
  ...
}
b
Whoa, a big thanks to all of you for such a fast reaction! I really appreciate it! The thing that stumbles me is that if I hoover under the property itself it says that undefined is legal input.
It feels like I'm missing some important knowledge. Nevertheless, thank you again! It's fixed.
a
That says that
loadBalancerSourceRanges
can be
undefined
. However, if you do provide an array to
loadBalancerSourceRanges
, then the members of that array cannot be
undefined
. You were effectively setting
loadBalancerSourceRanges
to
['10.0.0.0/8', undefined]
, which is not allowed.
👍 1
🙏 1