-
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
datasource/launch_template: Add new datasource #6064
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 @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, |
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 name
attribute here should be Required: true
and have Optional: true
and Computed: true
removed. 👍
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Optional: 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.
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. 😄
* cleaned up schema * added basic test * added docs
I added the tests you provided. How much additional verification needs to be added to that? |
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 is a great start -- lets get this in and iterate if necessary. Thanks, @WhileLoop! 🚀
--- PASS: TestAccAWSLaunchTemplateDataSource_basic (5.03s)
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. |
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! |
Fixes #5272
Changes proposed in this pull request:
Output from acceptance testing: