-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
New Resource: aws_launch_template #2927
Conversation
I don't think having to configure two resources ( Having a boolean |
Terraform core provides a lifecycle configuration block for all resources that allows you to ignore certain attributes you don't want to track: https://www.terraform.io/docs/configuration/resources.html#ignore_changes e.g. this will create an ECS service with a desired count of 1 (or import with whatever value) and ignore any changes resource "aws_ecs_service" "example" {
# other configuration
desired_count = 1
lifecycle {
ignore_changes = ["desired_count"]
}
} |
@bflad Is that only for explicitly defined fields or computed values as well? As long as this feature is implemented in a way that the default version attribute can be ignored with this methodology, that sounds great to me. |
06830e6
to
8675237
Compare
Would appreciate some eyes on this PR so far.
|
95af11a
to
4b30fd6
Compare
4b30fd6
to
f99fe1b
Compare
I think this is ready to remove to the WIP from this PR |
after rebase and added documentation: ==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSLaunchTemplate_ -timeout 120m
=== RUN TestAccAWSLaunchTemplate_basic
--- PASS: TestAccAWSLaunchTemplate_basic (12.32s)
=== RUN TestAccAWSLaunchTemplate_data
--- PASS: TestAccAWSLaunchTemplate_data (10.72s)
=== RUN TestAccAWSLaunchTemplate_update
--- PASS: TestAccAWSLaunchTemplate_update (19.42s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 42.505s``` |
ac7bc33
to
4a26f38
Compare
rebase again
|
Currently occasional cpu spike cause the t2 instance to go down and new instances are unable to bootstrap (upgrades) Until hashicorp/terraform-provider-aws#2927 becomes available, move all critical instances on non-metered cpu instances types
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.
Hi @kl4w! 👋 Thank you very much for this contribution! Overall this pull request is in great shape (don't let the number of comments distract from that 😄 ). You did a fantastic job implementing the crazy nested schema here.
Please check out the feedback and let me know if you have any questions or do not have time to implement any of them.
Aside: For this resource especially, I would also suggest running the acceptance testing with TF_SCHEMA_PANIC_ON_ERROR=1
just in case you missed setting any of the API attributes properly (types, etc.) back into the Terraform state, but it looks like you did a really good job returning errors for d.Set()
.
aws/resource_aws_launch_template.go
Outdated
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
const awsSpotInstanceTimeLayout = "2006-01-02T15:04:05Z" |
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.
We should use RFC3339 instead of our own custom time layout. 👍
aws/resource_aws_launch_template.go
Outdated
"description": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { |
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.
This can be simplified with:
ValidateFunc: validation.StringLenBetween(0, 255),
aws/resource_aws_launch_template.go
Outdated
}, | ||
}, | ||
|
||
"client_token": { |
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.
This attribute is not necessary (nor would I recommend) exposing. 👍
aws/resource_aws_launch_template.go
Outdated
Optional: true, | ||
}, | ||
"ebs": { | ||
Type: schema.TypeSet, |
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.
To simplify the implementation and future maintenance, we can use schema.TypeList
here 👍
aws/resource_aws_launch_template.go
Outdated
}, | ||
|
||
"instance_market_options": { | ||
Type: schema.TypeSet, |
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.
To simply the implementation and future maintenance, this can be schema.TypeList
👍
aws/resource_aws_launch_template.go
Outdated
s := []interface{}{} | ||
for _, v := range m { | ||
mapping := map[string]interface{}{ | ||
"device_name": *v.DeviceName, |
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.
Rather than risk panics on nil dereferencing, we should switch anything using *thing
to the appropriate SDK method that will set it to the zero value for the type: e.g. aws.StringValue(v.DeviceName)
This should repeated everywhere below.
resource.TestCheckResourceAttr(resName, "default_version", "1"), | ||
resource.TestCheckResourceAttr(resName, "latest_version", "1"), | ||
), | ||
}, |
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.
Let's add a TestStep
here that imports the resource and ensures the Terraform state matches what is expected 👍
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
resource.TestCheckResourceAttr(resName, "vpc_security_group_ids.#", "1"), | ||
resource.TestCheckResourceAttr(resName, "tag_specifications.#", "1"), | ||
), | ||
}, |
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.
Let's add a TestStep
here that imports the resource and ensures the Terraform state matches what is expected 👍
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
resource.TestCheckResourceAttr(resName, "latest_version", "2"), | ||
resource.TestCheckResourceAttrSet(resName, "image_id"), | ||
), | ||
}, |
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.
Let's add a TestStep
here that imports the resource and ensures the Terraform state matches what is expected 👍
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
} | ||
} | ||
|
||
ae, ok := err.(awserr.Error) |
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.
This can be simplified with if isAWSErr(err, "InvalidLaunchTemplateId.NotFound", "") {
👍 (replacing the middle with an SDK constant if available)
To echo @bflad, thank-you very much! This will definitely be useful. |
aws/resource_aws_launch_template.go
Outdated
@@ -277,34 +279,31 @@ func resourceAwsLaunchTemplate() *schema.Resource { | |||
Optional: true, | |||
}, | |||
"security_groups": { | |||
Type: schema.TypeSet, |
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.
These (security_groups
, ipv6_addresses
, and ipv4_addresses
) will likely need to remain Type: TypeSet
(just needed the Set: schema.HashString
removed) as the API likely does not return them in a consistent order. We'll find out!
aws/resource_aws_launch_template.go
Outdated
@@ -358,21 +362,19 @@ func resourceAwsLaunchTemplate() *schema.Resource { | |||
}, | |||
|
|||
"security_group_names": { | |||
Type: schema.TypeSet, |
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.
Similar note here about security_group_names
and vpc_security_group_ids
-- we shall see!
aws/resource_aws_launch_template.go
Outdated
"volume_type": *v.Ebs.VolumeType, | ||
"delete_on_termination": aws.BoolValue(v.Ebs.DeleteOnTermination), | ||
"encrypted": aws.BoolValue(v.Ebs.Encrypted), | ||
"volume_size": aws.Int64Value(v.Ebs.VolumeSize), |
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.
Any of these aws.Int64Value()
calls will need to be wrapped in int(aws.Int64Value())
since Terraform's TypeInt
is a regular int
Made modifications based off of the review. Can someone please advise on the import? I'm having test failures after adding the import step verification Without import
With import:
|
@kl4w generally that means |
aws/resource_aws_launch_template.go
Outdated
d.Set("instance_type", ltData.InstanceType) | ||
d.Set("kernel_id", ltData.KernelId) | ||
d.Set("key_name", ltData.KeyName) | ||
d.Set("monitoring", ltData.Monitoring) |
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.
This needs to be updated to err check (since its non-scalar now) as well as correctly handle the new nested structure:
if err := d.Set("monitoring", getMonitoring(ltData.Monitoring)); err != nil {
return err
}
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.
ahhh makes sense. Thank you. I'll make those changes now.
aws/resource_aws_launch_template.go
Outdated
d.Set("kernel_id", ltData.KernelId) | ||
d.Set("key_name", ltData.KeyName) | ||
d.Set("monitoring", ltData.Monitoring) | ||
d.Set("ram_dist_id", ltData.RamDiskId) |
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.
Typo: 😅 d.Set("ram_disk_id", ltData.RamDiskId)
(FYI you can find these by running the acceptance testing with TF_SCHEMA_PANIC_ON_ERROR=1
as well as the import testing that noticed it)
|
Do you have a second to update the |
|
||
key_name = "test" | ||
|
||
monitoring = true |
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.
I'll fix this up post merge 👍
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.
ahh thanks. I was going to update the documentation as well on this branch. Do you want me to hold off?
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.
@kl4w you are about to make a large amount of people happy! Great work on this and thanks for sticking through the crazy schema issues! 🚀 💯 🥇
5 tests passed (all tests)
=== RUN TestAccAWSLaunchTemplate_data
--- PASS: TestAccAWSLaunchTemplate_data (6.54s)
=== RUN TestAccAWSLaunchTemplate_basic
--- PASS: TestAccAWSLaunchTemplate_basic (6.60s)
=== RUN TestAccAWSLaunchTemplate_importBasic
--- PASS: TestAccAWSLaunchTemplate_importBasic (7.32s)
=== RUN TestAccAWSLaunchTemplate_importData
--- PASS: TestAccAWSLaunchTemplate_importData (7.35s)
=== RUN TestAccAWSLaunchTemplate_update
--- PASS: TestAccAWSLaunchTemplate_update (11.30s)
This has been released in version 1.15.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
To address #2505
I've created an initial
LaunchTemplate
resource but unsure how to handle versions and would like input/help.Creating a new launch template is also conceptually creating the first
LaunchTemplateVersion
.If a new
LaunchTemplateVersion
resource is to be created, it seems weird that it may/should also update thedefaultVersion
andlatestVersion
attributes of theLaunchTemplate
. Deleting a launch template also deletes all existing versions.I was thinking about combining the concept of
LaunchTemplate
andLaunchTemplateVersion
such that an update of theLaunchTemplate
creates aLaunchTemplateVersion
. This results in a singleLaunchTemplate
in the resulting state. The question is how to handle the versioning of the launch template and how to handle thesourceVersion
parameter when creating a newLaunchTemplateVersion
.Combining
LaunchTemplate
andLaunchTemplateVersion
also means that it does not allow as much freedom managing versions, and may mean that creating any resource using theLaunchTemplate
may have to use thelatestVersion
.Another idea that I was throwing around was create both the
LaunchTemplate
andLaunchTemplateVersion
resources but remove thelaunchTemplateData
attribute from theLaunchTemplate
. This would mean that theLaunchTemplate
is used more as a versioning reference, and the data is always held in theLaunchTemplateVersion
resource. However this would also mean that both resources would be required in order to create a useful launch template.Thoughts/ideas?