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

r/launch_template: only set credit specification if t2 instance type #5190

Merged
merged 1 commit into from
Jul 17, 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
14 changes: 9 additions & 5 deletions aws/resource_aws_launch_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"strconv"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -510,8 +511,10 @@ func resourceAwsLaunchTemplateRead(d *schema.ResourceData, meta interface{}) err
return err
}

if err := d.Set("credit_specification", getCreditSpecification(ltData.CreditSpecification)); err != nil {
return err
if strings.HasPrefix(aws.StringValue(ltData.InstanceType), "t2") {
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not think we should perform this conditional on read as it can potentially break modules expecting credit_specification for outputs (this will be less of a concern with Terraform 0.12). I'll try removing this on merge.

if err := d.Set("credit_specification", getCreditSpecification(ltData.CreditSpecification)); err != nil {
return err
}
}

if err := d.Set("elastic_gpu_specifications", getElasticGpuSpecifications(ltData.ElasticGpuSpecifications)); err != nil {
Expand Down Expand Up @@ -786,8 +789,9 @@ func buildLaunchTemplateData(d *schema.ResourceData, meta interface{}) (*ec2.Req
opts.InstanceInitiatedShutdownBehavior = aws.String(v.(string))
}

if v, ok := d.GetOk("instance_type"); ok {
opts.InstanceType = aws.String(v.(string))
instanceType := d.Get("instance_type").(string)
if instanceType != "" {
opts.InstanceType = aws.String(instanceType)
}

if v, ok := d.GetOk("kernel_id"); ok {
Expand Down Expand Up @@ -828,7 +832,7 @@ func buildLaunchTemplateData(d *schema.ResourceData, meta interface{}) (*ec2.Req
opts.BlockDeviceMappings = blockDeviceMappings
}

if v, ok := d.GetOk("credit_specification"); ok {
if v, ok := d.GetOk("credit_specification"); ok && strings.HasPrefix(instanceType, "t2") {
cs := v.([]interface{})

if len(cs) > 0 {
Expand Down
29 changes: 29 additions & 0 deletions aws/resource_aws_launch_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,25 @@ func TestAccAWSLaunchTemplate_tags(t *testing.T) {
})
}

func TestAccAWSLaunchTemplate_nonBurstable(t *testing.T) {
var template ec2.LaunchTemplate
resName := "aws_launch_template.foo"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSLaunchTemplateDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLaunchTemplateConfig_nonBurstable,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLaunchTemplateExists(resName, &template),
),
},
},
})
}

func testAccCheckAWSLaunchTemplateExists(n string, t *ec2.LaunchTemplate) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -341,3 +360,13 @@ resource "aws_launch_template" "foo" {
}
`, rInt)
}

const testAccAWSLaunchTemplateConfig_nonBurstable = `
resource "aws_launch_template" "foo" {
name = "non-burstable-launch-template"
instance_type = "m1.small"
credit_specification {
cpu_credits = "standard"
}
}
`