Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add serviceRole and instanceProfile to ClusterOptions #159

Merged
merged 11 commits into from
Jul 1, 2019
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### Improvements

- feature(cluster): Allow service role and instance profile to be injected during cluster creation
[#159](https://github.com/pulumi/pulumi-eks/pull/159)

## 0.18.7 (Released June 12, 2019)

### Improvements
Expand Down
32 changes: 26 additions & 6 deletions nodejs/eks/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,19 @@ export function createCore(name: string, args: ClusterOptions, parent: pulumi.Co
}

// Create the EKS service role
const eksRole = new ServiceRole(`${name}-eksRole`, {
let eksRole: pulumi.Output<aws.iam.Role>;
if (args.serviceRole) {
eksRole = pulumi.output(args.serviceRole);
} else {
eksRole = (new ServiceRole(`${name}-eksRole`, {
service: "eks.amazonaws.com",
description: "Allows EKS to manage clusters on your behalf.",
managedPolicyArns: [
"arn:aws:iam::aws:policy/AmazonEKSClusterPolicy",
"arn:aws:iam::aws:policy/AmazonEKSServicePolicy",
],
}, { parent: parent });
}, { parent: parent })).role;
VRanga000 marked this conversation as resolved.
Show resolved Hide resolved
}

// Create the EKS cluster security group
const eksClusterSecurityGroup = new aws.ec2.SecurityGroup(`${name}-eksClusterSecurityGroup`, {
Expand Down Expand Up @@ -144,7 +149,7 @@ export function createCore(name: string, args: ClusterOptions, parent: pulumi.Co

// Create the EKS cluster
const eksCluster = new aws.eks.Cluster(`${name}-eksCluster`, {
roleArn: eksRole.role.apply(r => r.arn),
roleArn: eksRole.apply(r => r.arn),
vpcConfig: { securityGroupIds: [ eksClusterSecurityGroup.id ], subnetIds: subnetIds },
version: args.version,
enabledClusterLogTypes: args.enabledClusterLogTypes,
Expand Down Expand Up @@ -216,9 +221,13 @@ export function createCore(name: string, args: ClusterOptions, parent: pulumi.Co
} else if (args.instanceRole) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a third branch of this if/else if/else if that also creates an InstanceProfile. I assume we need to update that one as well?

The branching here is a little wild, and probably eventually should get simplified down or refactored a bit - but that can be part of a a follow-up PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, currently the instanceprofile only seems to get created if a single iam role is passed in among the args. Presumably an instanceprofile (or profiles?) need to get get created in the "if" branch as well? In that branch, a list of roles are passed in. The only use case we currently have is when a single role is passed in, so I didn't pay attention to the other logical branches :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do need to make the change in the other branch as well to be correct here. We are allowing the user to pass an explicit InstanceRole they want to use, but then in some cases will ignore it and create a new one anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.. Ill address this shortly. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just pushed a commit for this.

// Create an instance profile if using a default node group
if (!args.skipDefaultNodeGroup) {
instanceProfile = new aws.iam.InstanceProfile(`${name}-instanceProfile`, {
role: args.instanceRole,
}, { parent: parent });
if (args.instanceProfileName) {
instanceProfile = aws.iam.InstanceProfile.get(args.instanceProfileName, args.instanceProfileName);
VRanga000 marked this conversation as resolved.
Show resolved Hide resolved
} else {
instanceProfile = new aws.iam.InstanceProfile(`${name}-instanceProfile`, {
role: args.instanceRole,
}, { parent: parent });
}
}

instanceRoleMappings = pulumi.output(args.instanceRole).apply(instanceRole =>
Expand Down Expand Up @@ -371,6 +380,17 @@ export interface ClusterOptions {
*/
instanceRole?: pulumi.Input<aws.iam.Role>;

/**
* Node instance profile - for worker nodes. If not supplied, it will be created.
*/
VRanga000 marked this conversation as resolved.
Show resolved Hide resolved
instanceProfileName?: string;

/**
* Service role for eks cluster
*
VRanga000 marked this conversation as resolved.
Show resolved Hide resolved
*/
serviceRole?: pulumi.Input<aws.iam.Role>;

/**
* This enables the advanced case of registering *many* IAM instance roles
* with the cluster for per node group IAM, instead of the simpler, shared case of `instanceRole`.
Expand Down