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

provider: Ensure validateTypeStringNullableBoolean accepts stringified "true" and "false" #5995

Merged
merged 1 commit into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions aws/resource_aws_launch_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,60 @@ func TestAccAWSLaunchTemplate_BlockDeviceMappings_EBS_DeleteOnTermination(t *tes
})
}

func TestAccAWSLaunchTemplate_EbsOptimized(t *testing.T) {
var template ec2.LaunchTemplate
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_launch_template.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSLaunchTemplateDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLaunchTemplateConfig_EbsOptimized(rName, "true"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLaunchTemplateExists(resourceName, &template),
resource.TestCheckResourceAttr(resourceName, "ebs_optimized", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAWSLaunchTemplateConfig_EbsOptimized(rName, "false"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLaunchTemplateExists(resourceName, &template),
resource.TestCheckResourceAttr(resourceName, "ebs_optimized", "false"),
),
},
{
Config: testAccAWSLaunchTemplateConfig_EbsOptimized(rName, "\"true\""),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLaunchTemplateExists(resourceName, &template),
resource.TestCheckResourceAttr(resourceName, "ebs_optimized", "true"),
),
},
{
Config: testAccAWSLaunchTemplateConfig_EbsOptimized(rName, "\"false\""),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLaunchTemplateExists(resourceName, &template),
resource.TestCheckResourceAttr(resourceName, "ebs_optimized", "false"),
),
},
{
Config: testAccAWSLaunchTemplateConfig_EbsOptimized(rName, "\"\""),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLaunchTemplateExists(resourceName, &template),
resource.TestCheckResourceAttr(resourceName, "ebs_optimized", ""),
),
},
},
})
}

func TestAccAWSLaunchTemplate_data(t *testing.T) {
var template ec2.LaunchTemplate
resName := "aws_launch_template.foo"
Expand Down Expand Up @@ -598,6 +652,15 @@ resource "aws_autoscaling_group" "test" {
`, rName, deleteOnTermination, rName)
}

func testAccAWSLaunchTemplateConfig_EbsOptimized(rName, ebsOptimized string) string {
return fmt.Sprintf(`
resource "aws_launch_template" "test" {
ebs_optimized = %s # allows "", false, true, "false", "true" values
name = %q
}
`, ebsOptimized, rName)
}

func testAccAWSLaunchTemplateConfig_data(rInt int) string {
return fmt.Sprintf(`
resource "aws_launch_template" "foo" {
Expand Down
2 changes: 1 addition & 1 deletion aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func validateTypeStringNullableBoolean(v interface{}, k string) (ws []string, es
return
}

for _, str := range []string{"", "0", "1"} {
for _, str := range []string{"", "0", "1", "false", "true"} {
if value == str {
return
}
Expand Down
6 changes: 6 additions & 0 deletions aws/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ func TestValidateTypeStringNullableBoolean(t *testing.T) {
{
val: "1",
},
{
val: "true",
},
{
val: "false",
},
{
val: "invalid",
expectedErr: regexp.MustCompile(`to be one of \["", false, true\]`),
Expand Down