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

r/aws_launch_template: some more fixes #4367

Merged
merged 1 commit into from
May 11, 2018
Merged

r/aws_launch_template: some more fixes #4367

merged 1 commit into from
May 11, 2018

Conversation

stefansundin
Copy link
Contributor

@stefansundin stefansundin commented Apr 26, 2018

The first fix is trivial: device_index can be 0. I don't know if it's even desirable to keep it optional, since the console defaults the value to 0 if you do not fill in the field. If you add multiple devices and leave the index empty, the console will also increment them automatically, i.e. "eth0", "eth1", etc. Maybe we should do the same? I haven't tried launching an instance with a network interface without an index, so if that breaks then this is probably desirable.

The second fix is very incomplete. The thing is that almost all of the boolean values are really optional, but terraform defaults them to false. There is no way to leave them undefined. So terraform is not able to fully configure those properties. I tried making it a string, that way we can have the values "", "true", and "false". But then we lose the ability to just use true or false without quotes in the terraform code, which is kind of confusing for users.

I first tried this to only set it if it was defined as either true or false, but it did not work.

if v, ok := ni["associate_public_ip_address"]; ok {
	networkInterface.AssociatePublicIpAddress = aws.Bool(v.(bool))
}

I tried to use Default: nil like this, but it did not work. Perhaps the schema could be enhanced to allow this to make the code above work?

"associate_public_ip_address": {
	Type:     schema.TypeBool,
	Optional: true,
	Default:  nil,
},

But it still defaulted to false.

I then tried this, which did work, but there must be a better way.

"associate_public_ip_address": {
	Type:     schema.TypeString,
	Optional: true,
	ValidateFunc: validation.StringInSlice([]string{
		"true",
		"false",
	}, false),
},

So this affects any property that can be true, false, or undefined ("Do not include in template"). See screenshot:
screen shot 2018-04-26 at 07 45 27

I was going to fix the network interface security groups, but thankfully @kl4w opened his PR first which is much better than my fix. #4364

@ghost ghost added size/XS Managed by automation to categorize the size of a PR. size/S Managed by automation to categorize the size of a PR. and removed size/XS Managed by automation to categorize the size of a PR. labels Apr 26, 2018
@bflad
Copy link
Contributor

bflad commented Apr 26, 2018

@stefansundin during create/update does if v, ok := d.GetOkExists("attribute_name"); ok {workaround the boolean issue? We can do full if apiAttribute != nil { checks during read to prevent setting the attribute instead of just using aws.BoolValue() (which will default to false)

@bflad
Copy link
Contributor

bflad commented Apr 26, 2018

I'm guessing neither will help in this situation though 🙁

@bflad bflad added bug Addresses a defect in current functionality. service/elbv2 Issues and PRs that pertain to the elbv2 service. labels Apr 26, 2018
@bflad
Copy link
Contributor

bflad commented Apr 26, 2018

I think we might want to making each fix/enhancement individual PRs. Starting to see lots of overlapping work in this resource. See also #4344

@@ -952,7 +955,7 @@ func readNetworkInterfacesFromConfig(ni map[string]interface{}) *ec2.LaunchTempl
networkInterface.Description = aws.String(v)
}

if v, ok := ni["device_index"].(int); ok && v != 0 {
if v, ok := ni["device_index"].(int); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please switch to just this change so we can close #4475 for now?

Choose a reason for hiding this comment

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

This might not suffice. I had the resource created without this change, then changed the code, then did terraform apply again. Terraform wasn't going to update/recreate the resource, I had to destroy it manually.

Copy link
Contributor

Choose a reason for hiding this comment

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

Did it automatically assign device_index 0? I believe that's the behavior when its not supplied (auto incrementing from there).

Choose a reason for hiding this comment

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

No, it was missing completely. DescribeLaunchTemplateVersions returned:

"NetworkInterfaces": [
    {
        "AssociatePublicIpAddress": false,
        "DeleteOnTermination": false,
        "Ipv6AddressCount": 0,
        "SecondaryPrivateIpAddressCount": 0,
        "SubnetId": "subnet-xxxxxxxx"
    }
],

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bflad Done, sorry about the delay. I haven't had time to check back on this.

@ghost ghost added size/XS Managed by automation to categorize the size of a PR. and removed size/S Managed by automation to categorize the size of a PR. labels May 8, 2018
@ayarmoluk17
Copy link

Can we merge this one in? launch template is still unusable with ASG because of this. Using template with ASG in VPC requires device index of 0 https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-asg-launch-template.html

With fix merged it works perfectly for me.

@bflad bflad added this to the v1.19.0 milestone May 11, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Thanks so much for this @stefansundin -- let's get this in to fix handling for ASGs 🚀

@bflad bflad merged commit f7b62d7 into hashicorp:master May 11, 2018
bflad added a commit that referenced this pull request May 11, 2018
@bflad
Copy link
Contributor

bflad commented May 17, 2018

This has been released in version 1.19.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 5, 2020

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!

@ghost ghost locked and limited conversation to collaborators Apr 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/elbv2 Issues and PRs that pertain to the elbv2 service. size/XS Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants