Skip to content

Commit

Permalink
Merge pull request #18610 from tomelliff/add-ecs-task-def-family-vali…
Browse files Browse the repository at this point in the history
…dation

Add ECS task definition family validation to match API requirements
  • Loading branch information
YakDriver authored Jan 7, 2022
2 parents f123ea4 + d6a8f3d commit 6d88292
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/18610.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_ecs_task_definition: Add plan time validation for `family`
```
12 changes: 8 additions & 4 deletions internal/service/ecs/task_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"log"
"regexp"
"strings"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -66,10 +67,13 @@ func ResourceTaskDefinition() *schema.Resource {
},

"family": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 255),
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 255),
validation.StringMatch(regexp.MustCompile("^[0-9A-Za-z_-]+$"), "see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_TaskDefinition.html"),
),
},

"revision": {
Expand Down
7 changes: 4 additions & 3 deletions internal/service/ecs/task_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/service/ecs"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -174,7 +175,7 @@ func TestAccECSTaskDefinition_withRuntimePlatform(t *testing.T) {
resourceName := "aws_ecs_task_definition.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartition(endpoints.AwsPartitionID, t) }, // runtime platform not support on GovCloud
ErrorCheck: acctest.ErrorCheck(t, ecs.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckTaskDefinitionDestroy,
Expand Down Expand Up @@ -207,7 +208,7 @@ func TestAccECSTaskDefinition_Fargate_withRuntimePlatform(t *testing.T) {
resourceName := "aws_ecs_task_definition.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartition(endpoints.AwsPartitionID, t) }, // runtime platform not support on GovCloud
ErrorCheck: acctest.ErrorCheck(t, ecs.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckTaskDefinitionDestroy,
Expand Down Expand Up @@ -240,7 +241,7 @@ func TestAccECSTaskDefinition_Fargate_withRuntimePlatformWithoutArch(t *testing.
resourceName := "aws_ecs_task_definition.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartition(endpoints.AwsPartitionID, t) }, // runtime platform not support on GovCloud
ErrorCheck: acctest.ErrorCheck(t, ecs.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckTaskDefinitionDestroy,
Expand Down

0 comments on commit 6d88292

Please sign in to comment.