-
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
d/launch_configuration: new data source #3624
Conversation
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 👋 Thanks for submitting this!
I left some initial feedback below. Can you please take a look and let us know if you have any questions or do not have time to implement the feedback? Thanks!
return fmt.Errorf("Error retrieving launch configuration: %s", err) | ||
} | ||
|
||
lc := describConfs.LaunchConfigurations[0] |
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 prevent potential panics, we should perform a nil
check on describConfs
and len()
check on describConfs.LaunchConfigurations
, e.g.
if describConfs == nil || len(describConfs.LaunchConfigurations) == 0 {
return errors.New("No matching Launch Configuration found")
}
if len(describConfs.LaunchConfigurations) > 1 {
return errors.New("Multiple matching Launch Configurations found")
}
d.Set("ebs_optimized", lc.EbsOptimized) | ||
d.Set("spot_price", lc.SpotPrice) | ||
d.Set("enable_monitoring", lc.InstanceMonitoring.Enabled) | ||
d.Set("security_groups", lc.SecurityGroups) |
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.
When using d.Set()
with aggregate types (TypeList, TypeSet, TypeMap), we should perform error checking to prevent issues where the code is not properly able to set the Terraform state. e.g.
if err := d.Set("security_groups", lc.SecurityGroups); err != nil {
return fmt.Errorf("error setting security_groups: %s", err)
}
I believe in this case, you might discover an error about types. 😄
d.Set("associate_public_ip_address", lc.AssociatePublicIpAddress) | ||
|
||
d.Set("vpc_classic_link_id", lc.ClassicLinkVPCId) | ||
d.Set("vpc_classic_link_security_groups", lc.ClassicLinkVPCSecurityGroups) |
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.
When using d.Set()
with aggregate types (TypeList, TypeSet, TypeMap), we should perform error checking to prevent issues where the code is not properly able to set the Terraform state. e.g.
if err := d.Set("vpc_classic_link_security_groups", lc. ClassicLinkVPCSecurityGroups); err != nil {
return fmt.Errorf("error setting vpc_classic_link_security_groups: %s", err)
}
I believe in this case, you might discover an error about types. 😄
d.Set("iam_instance_profile", lc.IamInstanceProfile) | ||
d.Set("ebs_optimized", lc.EbsOptimized) | ||
d.Set("spot_price", lc.SpotPrice) | ||
d.Set("enable_monitoring", lc.InstanceMonitoring.Enabled) |
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 prevent potential panics, we should nil
check lc.InstanceMonitoring
first and default it otherwise, e.g.
d.Set("enable_monitoring", false)
if lc.InstanceMonitoring != nil {
d.Set("enable_monitoring", lc.InstanceMonitoring.Enabled)
}
Provides a Launch Configuration data source. | ||
--- | ||
|
||
# aws_launch_configuration |
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 PR probably predates when we applied this across the provider, but can you please prepend Data Source:
to the header, e.g. Data Source: aws_launch_configuration
The following attributes are exported: | ||
|
||
* `id` - The ID of the launch configuration. | ||
* `name` - The name of the launch configuration. |
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.
Minor nitpick: Can you please alphabetize the attributes here?
* `user_data` - The user data of the instance. | ||
* `enable_monitoring` - Whether detailed monitoring is enabled. | ||
* `ebs_optimized` - Whether the launched EC2 instance will be EBS-optimized. | ||
* `root_block_device` - The root block device of the instance. |
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 *_block_device
attributes are nested and the documentation should list out what those nested attributes are
2064a33
to
40d6ecf
Compare
@bflad rebased, made the changes as recommended and also fixed the setting of security groups:
|
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.
Thanks @kl4w! Looks good! 🚀
make testacc TEST=./aws TESTARGS='-run=TestAccAWSLaunchConfigurationDataSource'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSLaunchConfigurationDataSource -timeout 120m
=== RUN TestAccAWSLaunchConfigurationDataSource_basic
--- PASS: TestAccAWSLaunchConfigurationDataSource_basic (17.81s)
=== RUN TestAccAWSLaunchConfigurationDataSource_securityGroups
--- PASS: TestAccAWSLaunchConfigurationDataSource_securityGroups (30.58s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 48.432s
This has been released in version 1.26.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! |
Addresses #3245