Hi everyone. Trying Pulumi out for the first time ...
# golang
g
Hi everyone. Trying Pulumi out for the first time using
Go
and
AWS
. Having a weird issue when trying to update a stack containing
EKS
. No matter what changes I add (a new node group or simply adding a Helm chart) an
EKS cluster replace
is always included in the changes. Is there something obvious Im missing? Thank you!
b
Can you share your code?
g
Sure.
One sec.
Copy code
package main

import (
	"<http://github.com/pulumi/pulumi-aws/sdk/v5/go/aws/eks|github.com/pulumi/pulumi-aws/sdk/v5/go/aws/eks>"
	"<http://github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes|github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes>"
	"<http://github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/helm/v3|github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/helm/v3>"
	"<http://github.com/pulumi/pulumi/sdk/v3/go/pulumi|github.com/pulumi/pulumi/sdk/v3/go/pulumi>"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {

		clusterArgs := &eks.ClusterArgs{
			Name:    pulumi.String("contiamo-pulumi"),
			Version: pulumi.String("1.22"),
			RoleArn: pulumi.String("arn:aws:iam::REDACTED:role/eksClusterRole"),
			VpcConfig: &eks.ClusterVpcConfigArgs{
				SubnetIds: pulumi.StringArray{
					pulumi.String("subnet-0000000"),
					pulumi.String("subnet-0000000 "),
					pulumi.String("subnet-0000000"),
					pulumi.String("subnet-000000000"),
				},
			},
		}

		cluster, err := eks.NewCluster(ctx, "contiamo-pulumi", clusterArgs, nil)
		if err != nil {
			return err
		}
		nodeGroupArgs := &eks.NodeGroupArgs{
			ClusterName:   cluster.Name,
			NodeGroupName: pulumi.String("t3a-small"),
			NodeRoleArn:   pulumi.String("arn:aws:iam::990343961361:role/NodeInstanceRole"),
			SubnetIds: pulumi.StringArray{
				pulumi.String("subnet-074532a915dd26783"),
				pulumi.String("subnet-03207fffa807fb1e0"),
			},
			ScalingConfig: &eks.NodeGroupScalingConfigArgs{
				DesiredSize: <http://pulumi.Int|pulumi.Int>(1),
				MaxSize:     <http://pulumi.Int|pulumi.Int>(2),
				MinSize:     <http://pulumi.Int|pulumi.Int>(1),
			},
			InstanceTypes: pulumi.StringArray{
				pulumi.String("t3a.small"),
			},
		}
		nodeGroup, err := eks.NewNodeGroup(ctx, "t3a-small", nodeGroupArgs, nil)
		if err != nil {
			return err
		}

		// Create k8s provider. Used to interract with K8S:
		k8sProvider, err := kubernetes.NewProvider(ctx, "k8sprovider", &kubernetes.ProviderArgs{
			Kubeconfig: generateKubeconfig(cluster.Endpoint, cluster.CertificateAuthority.Data().Elem(), cluster.Name),
		}, pulumi.DependsOn([]pulumi.Resource{nodeGroup}))
		if err != nil {
			return err
		}

		nginx, err := helm.NewChart(ctx, "nginx", helm.ChartArgs{
			Chart:     pulumi.String("nginx-ingress"),
			Version:   pulumi.String("0.13.0"),
			Namespace: pulumi.String("kube-system"),
			Values: pulumi.Map{
				"controller": pulumi.Map{
					"replicaCount":         <http://pulumi.Int|pulumi.Int>(2),
					"enableLatencyMetrics": pulumi.Bool(true),
				},
				"prometheus": pulumi.Map{
					"create": pulumi.Bool(true),
				},
			},
			FetchArgs: &helm.FetchArgs{
				Repo: pulumi.String("<https://helm.nginx.com/stable>"),
			},
		}, pulumi.Provider(k8sProvider))
		if err != nil {
			return err
		}
		ctx.Export("wordpress", nginx.Resources)
		return nil
	})
}

//Create the KubeConfig Structure as per <https://docs.aws.amazon.com/eks/latest/userguide/create-kubeconfig.html>
func generateKubeconfig(clusterEndpoint pulumi.StringOutput, certData pulumi.StringOutput, clusterName pulumi.StringOutput) pulumi.StringOutput {
	return pulumi.Sprintf(`{
        "apiVersion": "v1",
        "clusters": [{
            "cluster": {
                "server": "%s",
                "certificate-authority-data": "%s"
            },
            "name": "kubernetes",
        }],
        "contexts": [{
            "context": {
                "cluster": "kubernetes",
                "user": "aws",
            },
            "name": "aws",
        }],
        "current-context": "aws",
        "kind": "Config",
        "users": [{
            "name": "aws",
            "user": {
                "exec": {
                    "apiVersion": "<http://client.authentication.k8s.io/v1alpha1|client.authentication.k8s.io/v1alpha1>",
                    "command": "aws-iam-authenticator",
                    "args": [
                        "token",
                        "-i",
                        "%s",
                    ],
                },
            },
        }],
    }`, clusterEndpoint, certData, clusterName)
}
In fact, even if I run
pulumi up
without having made any changes all the resources are planned to be
replaced
Looks like I figured it out. Turns out I had to provide all the missing parameters explicitly. The replacements were probably happening because some of the required resource name were generated automatically due to the fact that I wasn’t setting them explicitly.