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

r/opsworks_ecs_cluster_layer - add new resource #12495

Merged
merged 6 commits into from
Feb 23, 2022
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
3 changes: 3 additions & 0 deletions .changelog/12495.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_opsworks_ecs_cluster_layer
```
33 changes: 17 additions & 16 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1564,22 +1564,23 @@ func Provider() *schema.Provider {
"aws_networkfirewall_resource_policy": networkfirewall.ResourceResourcePolicy(),
"aws_networkfirewall_rule_group": networkfirewall.ResourceRuleGroup(),

"aws_opsworks_application": opsworks.ResourceApplication(),
"aws_opsworks_custom_layer": opsworks.ResourceCustomLayer(),
"aws_opsworks_ganglia_layer": opsworks.ResourceGangliaLayer(),
"aws_opsworks_haproxy_layer": opsworks.ResourceHAProxyLayer(),
"aws_opsworks_instance": opsworks.ResourceInstance(),
"aws_opsworks_java_app_layer": opsworks.ResourceJavaAppLayer(),
"aws_opsworks_memcached_layer": opsworks.ResourceMemcachedLayer(),
"aws_opsworks_mysql_layer": opsworks.ResourceMySQLLayer(),
"aws_opsworks_nodejs_app_layer": opsworks.ResourceNodejsAppLayer(),
"aws_opsworks_permission": opsworks.ResourcePermission(),
"aws_opsworks_php_app_layer": opsworks.ResourcePHPAppLayer(),
"aws_opsworks_rails_app_layer": opsworks.ResourceRailsAppLayer(),
"aws_opsworks_rds_db_instance": opsworks.ResourceRDSDBInstance(),
"aws_opsworks_stack": opsworks.ResourceStack(),
"aws_opsworks_static_web_layer": opsworks.ResourceStaticWebLayer(),
"aws_opsworks_user_profile": opsworks.ResourceUserProfile(),
"aws_opsworks_application": opsworks.ResourceApplication(),
"aws_opsworks_custom_layer": opsworks.ResourceCustomLayer(),
"aws_opsworks_ecs_cluster_layer": opsworks.ResourceEcsClusterLayer(),
"aws_opsworks_ganglia_layer": opsworks.ResourceGangliaLayer(),
"aws_opsworks_haproxy_layer": opsworks.ResourceHAProxyLayer(),
"aws_opsworks_instance": opsworks.ResourceInstance(),
"aws_opsworks_java_app_layer": opsworks.ResourceJavaAppLayer(),
"aws_opsworks_memcached_layer": opsworks.ResourceMemcachedLayer(),
"aws_opsworks_mysql_layer": opsworks.ResourceMySQLLayer(),
"aws_opsworks_nodejs_app_layer": opsworks.ResourceNodejsAppLayer(),
"aws_opsworks_permission": opsworks.ResourcePermission(),
"aws_opsworks_php_app_layer": opsworks.ResourcePHPAppLayer(),
"aws_opsworks_rails_app_layer": opsworks.ResourceRailsAppLayer(),
"aws_opsworks_rds_db_instance": opsworks.ResourceRDSDBInstance(),
"aws_opsworks_stack": opsworks.ResourceStack(),
"aws_opsworks_static_web_layer": opsworks.ResourceStaticWebLayer(),
"aws_opsworks_user_profile": opsworks.ResourceUserProfile(),

"aws_organizations_account": organizations.ResourceAccount(),
"aws_organizations_delegated_administrator": organizations.ResourceDelegatedAdministrator(),
Expand Down
26 changes: 26 additions & 0 deletions internal/service/opsworks/ecs_cluster_layer.go
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()
}
152 changes: 152 additions & 0 deletions internal/service/opsworks/ecs_cluster_layer_test.go
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)
}
Loading