From 685fdc2174642a42de1baa0700a84e64c8c0480d Mon Sep 17 00:00:00 2001 From: Chris Garvis Date: Mon, 11 Jun 2018 13:56:10 -0400 Subject: [PATCH 1/5] Add ComputePlatform to aws_codedeploy_app --- aws/resource_aws_codedeploy_app.go | 13 ++++++++ aws/resource_aws_codedeploy_app_test.go | 37 +++++++++++++++++++++ website/docs/r/codedeploy_app.html.markdown | 1 + 3 files changed, 51 insertions(+) diff --git a/aws/resource_aws_codedeploy_app.go b/aws/resource_aws_codedeploy_app.go index cf3dac3debf..9a688bc31e2 100644 --- a/aws/resource_aws_codedeploy_app.go +++ b/aws/resource_aws_codedeploy_app.go @@ -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 { @@ -26,6 +27,16 @@ func resourceAwsCodeDeployApp() *schema.Resource { ForceNew: true, }, + "compute_platform": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + codedeploy.ComputePlatformServer, + codedeploy.ComputePlatformLambda, + }, false), + Default: codedeploy.ComputePlatformServer, + }, + // The unique ID is set by AWS on create. "unique_id": &schema.Schema{ Type: schema.TypeString, @@ -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 diff --git a/aws/resource_aws_codedeploy_app_test.go b/aws/resource_aws_codedeploy_app_test.go index dd3a4ce7a94..37beae6391a 100644 --- a/aws/resource_aws_codedeploy_app_test.go +++ b/aws/resource_aws_codedeploy_app_test.go @@ -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" ) @@ -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 @@ -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" diff --git a/website/docs/r/codedeploy_app.html.markdown b/website/docs/r/codedeploy_app.html.markdown index 388c2266c33..971627de787 100644 --- a/website/docs/r/codedeploy_app.html.markdown +++ b/website/docs/r/codedeploy_app.html.markdown @@ -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`. ## Attribute Reference From f6cf7ee94a9c0ee29b4ea8a0c14d63fb4d20f814 Mon Sep 17 00:00:00 2001 From: Chris Garvis Date: Mon, 11 Jun 2018 15:30:37 -0400 Subject: [PATCH 2/5] Fixup markup --- website/docs/r/codedeploy_app.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/codedeploy_app.html.markdown b/website/docs/r/codedeploy_app.html.markdown index 971627de787..ab029119fa4 100644 --- a/website/docs/r/codedeploy_app.html.markdown +++ b/website/docs/r/codedeploy_app.html.markdown @@ -23,7 +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`. +* `compute_platform` - (Optional) The compute platform can either be `Server` or `Lambda`. ## Attribute Reference From 93d06c7aa71b4a27b91be485b5d16ac21d38dfef Mon Sep 17 00:00:00 2001 From: Chris Garvis Date: Thu, 14 Jun 2018 09:07:12 -0400 Subject: [PATCH 3/5] Add default value of `compute_platform` to docs --- website/docs/r/codedeploy_app.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/codedeploy_app.html.markdown b/website/docs/r/codedeploy_app.html.markdown index ab029119fa4..59f454b0440 100644 --- a/website/docs/r/codedeploy_app.html.markdown +++ b/website/docs/r/codedeploy_app.html.markdown @@ -23,7 +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`. +* `compute_platform` - (Optional) The compute platform can either be `Server` or `Lambda`. Default is `Server`. ## Attribute Reference From 547ad1078f3c19d9334199bba46aee25c634a534 Mon Sep 17 00:00:00 2001 From: Chris Garvis Date: Thu, 14 Jun 2018 09:07:44 -0400 Subject: [PATCH 4/5] Remove `&schema.Schema` --- aws/resource_aws_codedeploy_app.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aws/resource_aws_codedeploy_app.go b/aws/resource_aws_codedeploy_app.go index 9a688bc31e2..b26bcb5fc4f 100644 --- a/aws/resource_aws_codedeploy_app.go +++ b/aws/resource_aws_codedeploy_app.go @@ -21,13 +21,13 @@ func resourceAwsCodeDeployApp() *schema.Resource { Delete: resourceAwsCodeDeployAppDelete, Schema: map[string]*schema.Schema{ - "name": &schema.Schema{ + "name": { Type: schema.TypeString, Required: true, ForceNew: true, }, - "compute_platform": &schema.Schema{ + "compute_platform": { Type: schema.TypeString, Optional: true, ValidateFunc: validation.StringInSlice([]string{ @@ -38,7 +38,7 @@ func resourceAwsCodeDeployApp() *schema.Resource { }, // The unique ID is set by AWS on create. - "unique_id": &schema.Schema{ + "unique_id": { Type: schema.TypeString, Optional: true, Computed: true, From 13e67da35a78b6af63f044aba5eb0fde84d6a798 Mon Sep 17 00:00:00 2001 From: Chris Garvis Date: Thu, 14 Jun 2018 09:09:23 -0400 Subject: [PATCH 5/5] Test default value of `compute_platform` --- aws/resource_aws_codedeploy_app_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/resource_aws_codedeploy_app_test.go b/aws/resource_aws_codedeploy_app_test.go index 37beae6391a..16e8d8781e6 100644 --- a/aws/resource_aws_codedeploy_app_test.go +++ b/aws/resource_aws_codedeploy_app_test.go @@ -21,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"), ), },