-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
resource/aws_eks_node_group: Add launch_template configuration block #14639
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,36 @@ func resourceAwsEksNodeGroup() *schema.Resource { | |
Optional: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"launch_template": { | ||
Type: schema.TypeList, | ||
MaxItems: 1, | ||
Optional: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
ConflictsWith: []string{"launch_template.0.name"}, | ||
ValidateFunc: validateLaunchTemplateId, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
ConflictsWith: []string{"launch_template.0.id"}, | ||
ValidateFunc: validateLaunchTemplateName, | ||
}, | ||
"version": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringLenBetween(1, 255), | ||
}, | ||
}, | ||
}, | ||
}, | ||
"node_group_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
|
@@ -213,6 +243,10 @@ func resourceAwsEksNodeGroupCreate(d *schema.ResourceData, meta interface{}) err | |
input.Labels = stringMapToPointers(v) | ||
} | ||
|
||
if v := d.Get("launch_template").([]interface{}); len(v) > 0 { | ||
input.LaunchTemplate = expandEksLaunchTemplateSpecification(v) | ||
} | ||
|
||
if v, ok := d.GetOk("release_version"); ok { | ||
input.ReleaseVersion = aws.String(v.(string)) | ||
} | ||
|
@@ -303,6 +337,10 @@ func resourceAwsEksNodeGroupRead(d *schema.ResourceData, meta interface{}) error | |
return fmt.Errorf("error setting labels: %s", err) | ||
} | ||
|
||
if err := d.Set("launch_template", flattenEksLaunchTemplateSpecification(nodeGroup.LaunchTemplate)); err != nil { | ||
return fmt.Errorf("error setting launch_template: %s", err) | ||
} | ||
|
||
d.Set("node_group_name", nodeGroup.NodegroupName) | ||
d.Set("node_role_arn", nodeGroup.NodeRole) | ||
d.Set("release_version", nodeGroup.ReleaseVersion) | ||
|
@@ -374,19 +412,39 @@ func resourceAwsEksNodeGroupUpdate(d *schema.ResourceData, meta interface{}) err | |
} | ||
} | ||
|
||
if d.HasChanges("release_version", "version") { | ||
if d.HasChanges("launch_template", "release_version", "version") { | ||
input := &eks.UpdateNodegroupVersionInput{ | ||
ClientRequestToken: aws.String(resource.UniqueId()), | ||
ClusterName: aws.String(clusterName), | ||
Force: aws.Bool(d.Get("force_update_version").(bool)), | ||
NodegroupName: aws.String(nodeGroupName), | ||
} | ||
|
||
if v := d.Get("launch_template").([]interface{}); len(v) > 0 { | ||
input.LaunchTemplate = expandEksLaunchTemplateSpecification(v) | ||
|
||
// When returning Launch Template information, the API returns all | ||
// fields. Since both the id and name are saved to the Terraform | ||
// state for drift detection and the API returns the following | ||
// error if both are present during update: | ||
// InvalidParameterException: Either provide launch template ID or launch template name in the request. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will reach out to the EKS service team to see if they can remove this restriction. |
||
|
||
// Remove the name if there are no changes, to prefer the ID. | ||
if input.LaunchTemplate.Id != nil && input.LaunchTemplate.Name != nil && !d.HasChange("launch_template.0.name") { | ||
input.LaunchTemplate.Name = nil | ||
} | ||
|
||
// Otherwise, remove the ID, but only if both are present still. | ||
if input.LaunchTemplate.Id != nil && input.LaunchTemplate.Name != nil && !d.HasChange("launch_template.0.id") { | ||
input.LaunchTemplate.Id = nil | ||
} | ||
} | ||
|
||
if v, ok := d.GetOk("release_version"); ok && d.HasChange("release_version") { | ||
input.ReleaseVersion = aws.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("version"); ok { | ||
if v, ok := d.GetOk("version"); ok && d.HasChange("version") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. interesting, my only follow-up to this would be if we need to check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah i see |
||
input.Version = aws.String(v.(string)) | ||
} | ||
|
||
|
@@ -448,6 +506,30 @@ func resourceAwsEksNodeGroupDelete(d *schema.ResourceData, meta interface{}) err | |
return nil | ||
} | ||
|
||
func expandEksLaunchTemplateSpecification(l []interface{}) *eks.LaunchTemplateSpecification { | ||
if len(l) == 0 || l[0] == nil { | ||
return nil | ||
} | ||
|
||
m := l[0].(map[string]interface{}) | ||
|
||
config := &eks.LaunchTemplateSpecification{} | ||
|
||
if v, ok := m["id"].(string); ok && v != "" { | ||
config.Id = aws.String(v) | ||
} | ||
|
||
if v, ok := m["name"].(string); ok && v != "" { | ||
config.Name = aws.String(v) | ||
} | ||
|
||
if v, ok := m["version"].(string); ok && v != "" { | ||
config.Version = aws.String(v) | ||
} | ||
|
||
return config | ||
} | ||
|
||
func expandEksNodegroupScalingConfig(l []interface{}) *eks.NodegroupScalingConfig { | ||
if len(l) == 0 || l[0] == nil { | ||
return nil | ||
|
@@ -535,6 +617,28 @@ func flattenEksAutoScalingGroups(autoScalingGroups []*eks.AutoScalingGroup) []ma | |
return l | ||
} | ||
|
||
func flattenEksLaunchTemplateSpecification(config *eks.LaunchTemplateSpecification) []map[string]interface{} { | ||
if config == nil { | ||
return nil | ||
} | ||
|
||
m := map[string]interface{}{} | ||
|
||
if v := config.Id; v != nil { | ||
m["id"] = aws.StringValue(v) | ||
} | ||
|
||
if v := config.Name; v != nil { | ||
m["name"] = aws.StringValue(v) | ||
} | ||
|
||
if v := config.Version; v != nil { | ||
m["version"] = aws.StringValue(v) | ||
} | ||
|
||
return []map[string]interface{}{m} | ||
} | ||
|
||
func flattenEksNodeGroupResources(resources *eks.NodegroupResources) []map[string]interface{} { | ||
if resources == nil { | ||
return []map[string]interface{}{} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
UpdateNodegroupVersion
API currently returns an error if the name changes. 👍There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah i guess that's what they meant in
You can update a node group using a launch template only if the node group was originally deployed with a launch template
...on first pass, wording here made it seem like a launch template could mean the presence of 1 not necessarily the same one used at creation time