Skip to content

Commit

Permalink
Simplify examples
Browse files Browse the repository at this point in the history
  • Loading branch information
flostadler committed Oct 16, 2024
1 parent 8affc67 commit dd44cba
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/cluster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const cluster1 = new eks.Cluster(`${projectName}-1`, {
nodeAmiId: "ami-066e69f6f03b5383e",
});

export const defaultAsgArn: pulumi.Output<string> = cluster1.defaultNodeGroup.apply(ng => ng?.autoScalingGroup.arn ?? pulumi.output(""));
export const defaultAsgName: pulumi.Output<string> = cluster1.defaultNodeGroupAsgName;

const cluster2 = new eks.Cluster(`${projectName}-2`, {
vpcId: vpc.vpcId,
Expand Down
2 changes: 1 addition & 1 deletion examples/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestAccCluster(t *testing.T) {
info.Outputs["kubeconfig4"],
)

assert.NotEmpty(t, info.Outputs["defaultAsgArn"], "should have a default ASG")
assert.NotEmpty(t, info.Outputs["defaultAsgName"], "should have a default ASG")

// let's test there's a iamRoleArn specified for the cluster
assert.NotEmpty(t, info.Outputs["iamRoleArn"])
Expand Down
4 changes: 2 additions & 2 deletions examples/extra-sg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const nodeIngressRule = new aws.ec2.SecurityGroupRule("nodeIngressRule", {
fromPort: 0,
toPort: 65535,
protocol: "tcp",
securityGroupId: cluster.nodeSecurityGroup.apply((sg) => sg!.id),
securityGroupId: cluster.nodeSecurityGroupId,
sourceSecurityGroupId: customSecurityGroup.id,
});

Expand Down Expand Up @@ -108,6 +108,6 @@ const ng = new eks.NodeGroupV2("example-mng", {
amiId: "ami-066e69f6f03b5383e",
extraNodeSecurityGroups: [
customSecurityGroup, // Plain type
cluster.nodeSecurityGroup.apply(sg => sg!), // Input type
cluster.nodeSecurityGroupId, // Input type
],
});
13 changes: 5 additions & 8 deletions examples/oidc-iam-sa/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export const kubeconfig = cluster.kubeconfig;
if (!cluster?.core?.oidcProvider) {
throw new Error("Invalid cluster OIDC provider URL");
}
const clusterOidcProvider = cluster.core.oidcProvider;
export const clusterOidcProviderUrl = clusterOidcProvider.apply(u => u!.url);

// Setup Pulumi Kubernetes provider.
const provider = new k8s.Provider("eks-k8s", {
Expand All @@ -34,22 +32,21 @@ export const appsNamespaceName = appsNamespace.metadata.name;
// Create the new IAM policy for the Service Account using the
// AssumeRoleWebWebIdentity action.
const saName = "s3";
const oidcProviderArn = clusterOidcProvider.apply(o => o!.arn);
const saAssumeRolePolicy = pulumi.all([clusterOidcProviderUrl, oidcProviderArn, appsNamespaceName]).apply(([url, arn, namespace]) => aws.iam.getPolicyDocument({
const saAssumeRolePolicy = aws.iam.getPolicyDocument({
statements: [{
actions: ["sts:AssumeRoleWithWebIdentity"],
conditions: [{
test: "StringEquals",
values: [`system:serviceaccount:${namespace}:${saName}`],
variable: `${url.replace("https://", "")}:sub`,
values: [pulumi.interpolate`system:serviceaccount:${appsNamespaceName}:${saName}`],
variable: pulumi.interpolate`${cluster.oidcIssuer}:sub`,
}],
effect: "Allow",
principals: [{
identifiers: [arn],
identifiers: [cluster.oidcProviderArn],
type: "Federated",
}],
}],
}));
});

const saRole = new aws.iam.Role(saName, {
assumeRolePolicy: saAssumeRolePolicy.json,
Expand Down

0 comments on commit dd44cba

Please sign in to comment.