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

resource/aws_codedeploy_deployment_config: Force new resource for minimum_healthy_hosts updates #4194

Merged
merged 1 commit into from
Apr 13, 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
2 changes: 2 additions & 0 deletions aws/resource_aws_codedeploy_deployment_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func resourceAwsCodeDeployDeploymentConfig() *schema.Resource {
"type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
codedeploy.MinimumHealthyHostsTypeHostCount,
codedeploy.MinimumHealthyHostsTypeFleetPercent,
Expand All @@ -42,6 +43,7 @@ func resourceAwsCodeDeployDeploymentConfig() *schema.Resource {
"value": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
},
},
Expand Down
57 changes: 45 additions & 12 deletions aws/resource_aws_codedeploy_deployment_config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aws

import (
"errors"
"fmt"
"testing"

Expand All @@ -13,7 +14,7 @@ import (
)

func TestAccAWSCodeDeployDeploymentConfig_fleetPercent(t *testing.T) {
var config codedeploy.DeploymentConfigInfo
var config1, config2 codedeploy.DeploymentConfigInfo

rName := acctest.RandString(5)

Expand All @@ -23,21 +24,32 @@ func TestAccAWSCodeDeployDeploymentConfig_fleetPercent(t *testing.T) {
CheckDestroy: testAccCheckAWSCodeDeployDeploymentConfigDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSCodeDeployDeploymentConfigFleet(rName),
Config: testAccAWSCodeDeployDeploymentConfigFleet(rName, 75),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeDeployDeploymentConfigExists("aws_codedeploy_deployment_config.foo", &config),
testAccCheckAWSCodeDeployDeploymentConfigExists("aws_codedeploy_deployment_config.foo", &config1),
resource.TestCheckResourceAttr(
"aws_codedeploy_deployment_config.foo", "minimum_healthy_hosts.0.type", "FLEET_PERCENT"),
resource.TestCheckResourceAttr(
"aws_codedeploy_deployment_config.foo", "minimum_healthy_hosts.0.value", "75"),
),
},
{
Config: testAccAWSCodeDeployDeploymentConfigFleet(rName, 50),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeDeployDeploymentConfigExists("aws_codedeploy_deployment_config.foo", &config2),
testAccCheckAWSCodeDeployDeploymentConfigRecreated(&config1, &config2),
resource.TestCheckResourceAttr(
"aws_codedeploy_deployment_config.foo", "minimum_healthy_hosts.0.type", "FLEET_PERCENT"),
resource.TestCheckResourceAttr(
"aws_codedeploy_deployment_config.foo", "minimum_healthy_hosts.0.value", "50"),
),
},
},
})
}

func TestAccAWSCodeDeployDeploymentConfig_hostCount(t *testing.T) {
var config codedeploy.DeploymentConfigInfo
var config1, config2 codedeploy.DeploymentConfigInfo

rName := acctest.RandString(5)

Expand All @@ -47,15 +59,26 @@ func TestAccAWSCodeDeployDeploymentConfig_hostCount(t *testing.T) {
CheckDestroy: testAccCheckAWSCodeDeployDeploymentConfigDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSCodeDeployDeploymentConfigHostCount(rName),
Config: testAccAWSCodeDeployDeploymentConfigHostCount(rName, 1),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeDeployDeploymentConfigExists("aws_codedeploy_deployment_config.foo", &config),
testAccCheckAWSCodeDeployDeploymentConfigExists("aws_codedeploy_deployment_config.foo", &config1),
resource.TestCheckResourceAttr(
"aws_codedeploy_deployment_config.foo", "minimum_healthy_hosts.0.type", "HOST_COUNT"),
resource.TestCheckResourceAttr(
"aws_codedeploy_deployment_config.foo", "minimum_healthy_hosts.0.value", "1"),
),
},
{
Config: testAccAWSCodeDeployDeploymentConfigHostCount(rName, 2),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeDeployDeploymentConfigExists("aws_codedeploy_deployment_config.foo", &config2),
testAccCheckAWSCodeDeployDeploymentConfigRecreated(&config1, &config2),
resource.TestCheckResourceAttr(
"aws_codedeploy_deployment_config.foo", "minimum_healthy_hosts.0.type", "HOST_COUNT"),
resource.TestCheckResourceAttr(
"aws_codedeploy_deployment_config.foo", "minimum_healthy_hosts.0.value", "2"),
),
},
},
})
}
Expand Down Expand Up @@ -111,24 +134,34 @@ func testAccCheckAWSCodeDeployDeploymentConfigExists(name string, config *codede
}
}

func testAccAWSCodeDeployDeploymentConfigFleet(rName string) string {
func testAccCheckAWSCodeDeployDeploymentConfigRecreated(i, j *codedeploy.DeploymentConfigInfo) resource.TestCheckFunc {
return func(s *terraform.State) error {
if aws.TimeValue(i.CreateTime) == aws.TimeValue(j.CreateTime) {
return errors.New("CodeDeploy Deployment Config was not recreated")
}

return nil
}
}

func testAccAWSCodeDeployDeploymentConfigFleet(rName string, value int) string {
return fmt.Sprintf(`
resource "aws_codedeploy_deployment_config" "foo" {
deployment_config_name = "test-deployment-config-%s"
minimum_healthy_hosts {
type = "FLEET_PERCENT"
value = 75
value = %d
}
}`, rName)
}`, rName, value)
}

func testAccAWSCodeDeployDeploymentConfigHostCount(rName string) string {
func testAccAWSCodeDeployDeploymentConfigHostCount(rName string, value int) string {
return fmt.Sprintf(`
resource "aws_codedeploy_deployment_config" "foo" {
deployment_config_name = "test-deployment-config-%s"
minimum_healthy_hosts {
type = "HOST_COUNT"
value = 1
value = %d
}
}`, rName)
}`, rName, value)
}