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

Add ComputePlatform to aws_codedeploy_app #4811

Merged
merged 5 commits into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 13 additions & 0 deletions aws/resource_aws_codedeploy_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/codedeploy"
"github.com/hashicorp/terraform/helper/validation"
)

func resourceAwsCodeDeployApp() *schema.Resource {
Expand All @@ -26,6 +27,16 @@ func resourceAwsCodeDeployApp() *schema.Resource {
ForceNew: true,
},

"compute_platform": &schema.Schema{
Copy link
Contributor

@bflad bflad Jun 12, 2018

Choose a reason for hiding this comment

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

There are two subtle, but important bugs with this attribute currently. 😄

  • The read function is not calling d.Set("compute_platform", ...) which has two implications: Terraform cannot detect drift of the attribute and in absence of the d.Set() call with the value, Terraform core is silently passing the configuration value into the Terraform state (which is why the acceptance testing passes)
  • This attribute cannot be updated in UpdateApplication and therefore needs to be set as ForceNew: true to force new resource creation

One other minor nitpick: (the rest of the file hasn't been updated yet, but) as of Go 1.7, the &schema.Schema is extraneous as its defined by map[string]*schema.Schema above so we prefer to remove them now 👍

Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
codedeploy.ComputePlatformServer,
codedeploy.ComputePlatformLambda,
}, false),
Default: codedeploy.ComputePlatformServer,
Copy link
Contributor

Choose a reason for hiding this comment

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

We should check the default value in TestAccAWSCodeDeployApp_basic as well (when not provided in the test configuration):

resource.TestCheckResourceAttr("aws_codedeploy_app.foo", "compute_platform", "Server"),

},

// The unique ID is set by AWS on create.
"unique_id": &schema.Schema{
Type: schema.TypeString,
Expand All @@ -40,10 +51,12 @@ func resourceAwsCodeDeployAppCreate(d *schema.ResourceData, meta interface{}) er
conn := meta.(*AWSClient).codedeployconn

application := d.Get("name").(string)
computePlatform := d.Get("compute_platform").(string)
log.Printf("[DEBUG] Creating CodeDeploy application %s", application)

resp, err := conn.CreateApplication(&codedeploy.CreateApplicationInput{
ApplicationName: aws.String(application),
ComputePlatform: aws.String(computePlatform),
})
if err != nil {
return err
Expand Down
37 changes: 37 additions & 0 deletions aws/resource_aws_codedeploy_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/codedeploy"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
Expand All @@ -33,6 +34,34 @@ func TestAccAWSCodeDeployApp_basic(t *testing.T) {
})
}

func TestAccAWSCodeDeployApp_computePlatform(t *testing.T) {
rName := acctest.RandString(5)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSCodeDeployAppDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSCodeDeployAppConfigComputePlatform(rName, "Server"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeDeployAppExists("aws_codedeploy_app.foo"),
resource.TestCheckResourceAttr(
"aws_codedeploy_app.foo", "compute_platform", "Server"),
),
},
resource.TestStep{
Config: testAccAWSCodeDeployAppConfigComputePlatform(rName, "Lambda"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeDeployAppExists("aws_codedeploy_app.foo"),
resource.TestCheckResourceAttr(
"aws_codedeploy_app.foo", "compute_platform", "Lambda"),
),
},
},
})
}

func testAccCheckAWSCodeDeployAppDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).codedeployconn

Expand Down Expand Up @@ -70,6 +99,14 @@ func testAccCheckAWSCodeDeployAppExists(name string) resource.TestCheckFunc {
}
}

func testAccAWSCodeDeployAppConfigComputePlatform(rName string, value string) string {
return fmt.Sprintf(`
resource "aws_codedeploy_app" "foo" {
name = "test-codedeploy-app-%s"
compute_platform = "%s"
}`, rName, value)
}

var testAccAWSCodeDeployApp = `
resource "aws_codedeploy_app" "foo" {
name = "foo"
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/codedeploy_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ resource "aws_codedeploy_app" "foo" {
The following arguments are supported:

* `name` - (Required) The name of the application.
* `compute_platform` - (Optional) The compute platform can either be `Server` or `Lambda`.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should list the default of Server here 👍


## Attribute Reference

Expand Down