-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12495 from DrFaust92/r/opsworks_layer_ecs
r/opsworks_ecs_cluster_layer - add new resource
- Loading branch information
Showing
7 changed files
with
359 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-resource | ||
aws_opsworks_ecs_cluster_layer | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package opsworks | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/service/opsworks" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-aws/internal/verify" | ||
) | ||
|
||
func ResourceEcsClusterLayer() *schema.Resource { | ||
layerType := &opsworksLayerType{ | ||
TypeName: opsworks.LayerTypeEcsCluster, | ||
DefaultLayerName: "Ecs Cluster", | ||
|
||
Attributes: map[string]*opsworksLayerTypeAttribute{ | ||
"ecs_cluster_arn": { | ||
AttrName: opsworks.LayerAttributesKeysEcsClusterArn, | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: verify.ValidARN, | ||
}, | ||
}, | ||
} | ||
|
||
return layerType.SchemaResource() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package opsworks_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/service/opsworks" | ||
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
"github.com/hashicorp/terraform-provider-aws/internal/acctest" | ||
) | ||
|
||
// These tests assume the existence of predefined Opsworks IAM roles named `aws-opsworks-ec2-role` | ||
// and `aws-opsworks-service-role`. | ||
|
||
func TestAccOpsWorksEcsClusterLayer_basic(t *testing.T) { | ||
var opslayer opsworks.Layer | ||
stackName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) | ||
resourceName := "aws_opsworks_ecs_cluster_layer.test" | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(opsworks.EndpointsID, t) }, | ||
ErrorCheck: acctest.ErrorCheck(t, opsworks.EndpointsID), | ||
Providers: acctest.Providers, | ||
CheckDestroy: testAccCheckEcsClusterLayerDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccEcsClusterLayerBasic(stackName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckLayerExists(resourceName, &opslayer), | ||
resource.TestCheckResourceAttr(resourceName, "name", stackName), | ||
resource.TestCheckResourceAttrPair(resourceName, "ecs_cluster_arn", "aws_ecs_cluster.test", "arn"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccOpsWorksEcsClusterLayer_tags(t *testing.T) { | ||
var opslayer opsworks.Layer | ||
stackName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) | ||
resourceName := "aws_opsworks_ecs_cluster_layer.test" | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(opsworks.EndpointsID, t) }, | ||
ErrorCheck: acctest.ErrorCheck(t, opsworks.EndpointsID), | ||
Providers: acctest.Providers, | ||
CheckDestroy: testAccCheckEcsClusterLayerDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccEcsClusterLayerTags1Config(stackName, "key1", "value1"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckLayerExists(resourceName, &opslayer), | ||
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), | ||
resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), | ||
), | ||
}, | ||
{ | ||
Config: testAccEcsClusterLayerTags2Config(stackName, "key1", "value1updated", "key2", "value2"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckLayerExists(resourceName, &opslayer), | ||
resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), | ||
resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), | ||
resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), | ||
), | ||
}, | ||
{ | ||
Config: testAccEcsClusterLayerTags1Config(stackName, "key2", "value2"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckLayerExists(resourceName, &opslayer), | ||
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), | ||
resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckEcsClusterLayerDestroy(s *terraform.State) error { | ||
return testAccCheckLayerDestroy("aws_opsworks_ecs_cluster_layer", s) | ||
} | ||
|
||
func testAccEcsClusterLayerBasic(name string) string { | ||
return testAccStackVPCCreateConfig(name) + | ||
testAccCustomLayerSecurityGroups(name) + | ||
fmt.Sprintf(` | ||
resource "aws_ecs_cluster" "test" { | ||
name = %[1]q | ||
} | ||
resource "aws_opsworks_ecs_cluster_layer" "test" { | ||
stack_id = aws_opsworks_stack.tf-acc.id | ||
name = %[1]q | ||
ecs_cluster_arn = aws_ecs_cluster.test.arn | ||
custom_security_group_ids = [ | ||
aws_security_group.tf-ops-acc-layer1.id, | ||
aws_security_group.tf-ops-acc-layer2.id, | ||
] | ||
} | ||
`, name) | ||
} | ||
|
||
func testAccEcsClusterLayerTags1Config(name, tagKey1, tagValue1 string) string { | ||
return testAccStackVPCCreateConfig(name) + | ||
testAccCustomLayerSecurityGroups(name) + | ||
fmt.Sprintf(` | ||
resource "aws_ecs_cluster" "test" { | ||
name = %[1]q | ||
} | ||
resource "aws_opsworks_ecs_cluster_layer" "test" { | ||
stack_id = aws_opsworks_stack.tf-acc.id | ||
name = %[1]q | ||
ecs_cluster_arn = aws_ecs_cluster.test.arn | ||
custom_security_group_ids = [ | ||
aws_security_group.tf-ops-acc-layer1.id, | ||
aws_security_group.tf-ops-acc-layer2.id, | ||
] | ||
tags = { | ||
%[2]q = %[3]q | ||
} | ||
} | ||
`, name, tagKey1, tagValue1) | ||
} | ||
|
||
func testAccEcsClusterLayerTags2Config(name, tagKey1, tagValue1, tagKey2, tagValue2 string) string { | ||
return testAccStackVPCCreateConfig(name) + | ||
testAccCustomLayerSecurityGroups(name) + | ||
fmt.Sprintf(` | ||
resource "aws_ecs_cluster" "test" { | ||
name = %[1]q | ||
} | ||
resource "aws_opsworks_ecs_cluster_layer" "test" { | ||
stack_id = aws_opsworks_stack.tf-acc.id | ||
name = %[1]q | ||
ecs_cluster_arn = aws_ecs_cluster.test.arn | ||
custom_security_group_ids = [ | ||
aws_security_group.tf-ops-acc-layer1.id, | ||
aws_security_group.tf-ops-acc-layer2.id, | ||
] | ||
tags = { | ||
%[2]q = %[3]q | ||
%[4]q = %[5]q | ||
} | ||
} | ||
`, name, tagKey1, tagValue1, tagKey2, tagValue2) | ||
} |
Oops, something went wrong.