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 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
17 changes: 15 additions & 2 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 @@ -20,14 +21,24 @@ func resourceAwsCodeDeployApp() *schema.Resource {
Delete: resourceAwsCodeDeployAppDelete,

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Copy link
Contributor

Choose a reason for hiding this comment

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

😍

"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"compute_platform": {
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{
"unique_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
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
38 changes: 38 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 @@ -20,6 +21,7 @@ func TestAccAWSCodeDeployApp_basic(t *testing.T) {
resource.TestStep{
Config: testAccAWSCodeDeployApp,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("aws_codedeploy_app.foo", "compute_platform", "Server"),
testAccCheckAWSCodeDeployAppExists("aws_codedeploy_app.foo"),
),
},
Expand All @@ -33,6 +35,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 +100,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`. Default is `Server`.

## Attribute Reference

Expand Down