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

d/launch_configuration: new data source #3624

Merged
merged 4 commits into from
Jun 28, 2018

Conversation

kl4w
Copy link
Contributor

@kl4w kl4w commented Mar 5, 2018

Addresses #3245

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 (16.61s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	16.657s

@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Mar 5, 2018
@bflad bflad added new-data-source Introduces a new data source. service/autoscaling Issues and PRs that pertain to the autoscaling service. labels Mar 6, 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.

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]
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Jun 27, 2018
@kl4w kl4w force-pushed the data-source-launch-config branch from 2064a33 to 40d6ecf Compare June 28, 2018 15:25
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Jun 28, 2018
@kl4w
Copy link
Contributor Author

kl4w commented Jun 28, 2018

@bflad rebased, made the changes as recommended and also fixed the setting of security groups:

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 (16.48s)
=== RUN   TestAccAWSLaunchConfigurationDataSource_securityGroups
--- PASS: TestAccAWSLaunchConfigurationDataSource_securityGroups (30.21s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	46.729s

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 @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

@bflad bflad added this to the v1.26.0 milestone Jun 28, 2018
@bflad bflad merged commit 882af6d into hashicorp:master Jun 28, 2018
bflad added a commit that referenced this pull request Jun 28, 2018
@kl4w kl4w deleted the data-source-launch-config branch June 28, 2018 18:51
@bflad
Copy link
Contributor

bflad commented Jul 4, 2018

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.

@ghost
Copy link

ghost commented Apr 4, 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 4, 2020
@breathingdust breathingdust removed the waiting-response Maintainers are waiting on response from community or contributor. label Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-data-source Introduces a new data source. service/autoscaling Issues and PRs that pertain to the autoscaling service. size/L Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants