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

datasource/launch_template: Add new datasource #6064

Merged
merged 2 commits into from
Oct 4, 2018

Conversation

WhileLoop
Copy link
Contributor

Fixes #5272

Changes proposed in this pull request:

  • Ad new aws_launch_template datasource
    Output from acceptance testing:
$ make testacc TESTARGS='-run=TestAccAWSAvailabilityZones'
coming soon...
...

@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Oct 4, 2018
@bflad bflad added new-data-source Introduces a new data source. service/ec2 Issues and PRs that pertain to the ec2 service. labels Oct 4, 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 @WhileLoop 👋 Thanks for submitting this!

We'll need a few additional things before we can get this in as outlined in https://github.com/terraform-providers/terraform-provider-aws/blob/master/.github/CONTRIBUTING.md#new-resource

For the documentation, we'll need a new link added to website/aws.erb and a new documentation page: website/docs/d/launch_template.html.markdown

For the testing, can you please add some acceptance testing for this data source? Something like this should get you started in a new file aws/data_source_aws_launch_template_test.go:

package aws

import (
	"fmt"
	"regexp"
	"testing"

	"github.com/hashicorp/terraform/helper/acctest"
	"github.com/hashicorp/terraform/helper/resource"
)

func TestAccAWSLaunchTemplateDataSource_basic(t *testing.T) {
	rName := acctest.RandomWithPrefix("tf-acc-test")
	dataSourceName := "data.aws_launch_template.test"
	resourceName := "aws_launch_template.test"

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSLaunchTemplateDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccAWSLaunchTemplateDataSourceConfig_Basic(rName),
				Check: resource.ComposeTestCheckFunc(
					resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"),
					resource.TestCheckResourceAttrPair(resourceName, "default_version", dataSourceName, "default_version"),
					resource.TestCheckResourceAttrPair(resourceName, "latest_version", dataSourceName, "latest_version"),
					resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"),
				),
			},
		},
	})
}

func testAccAWSLaunchTemplateDataSourceConfig_Basic(rName string) string {
	return fmt.Sprintf(`
resource "aws_launch_template" "test" {
  name = %q
}

data "aws_launch_template" "test" {
  name = "${aws_launch_template.test.name}"
}
`, rName)
}

Which can be run via make testacc TEST=./aws TESTARGS='-run=TestAccAWSLaunchTemplateDataSource_'

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

The name attribute here should be Required: true and have Optional: true and Computed: true removed. 👍

},
"description": {
Type: schema.TypeString,
Optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

All attributes except name should be Computed: true with Optional: true and Required: true removed unless they are user configurable to specify how to find a launch template. 😄

aws/data_source_aws_launch_template.go Show resolved Hide resolved
@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Oct 4, 2018
* cleaned up schema
* added basic test
* added docs
@ghost ghost added documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Oct 4, 2018
@WhileLoop
Copy link
Contributor Author

I added the tests you provided. How much additional verification needs to be added to that?

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.

This is a great start -- lets get this in and iterate if necessary. Thanks, @WhileLoop! 🚀

--- PASS: TestAccAWSLaunchTemplateDataSource_basic (5.03s)

@bflad bflad added this to the v1.40.0 milestone Oct 4, 2018
@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Oct 4, 2018
@bflad bflad merged commit da1691a into hashicorp:master Oct 4, 2018
bflad added a commit that referenced this pull request Oct 4, 2018
@bflad
Copy link
Contributor

bflad commented Oct 10, 2018

This has been released in version 1.40.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 3, 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 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. new-data-source Introduces a new data source. service/ec2 Issues and PRs that pertain to the ec2 service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New datasource request: aws_launch_template
3 participants