From de1f80ded0533d4404b231d22c14ac7dc43355bf Mon Sep 17 00:00:00 2001 From: stack72 Date: Mon, 12 Aug 2019 11:48:04 +0300 Subject: [PATCH] resource/ecs_cluster: Add ability to enable ECS Cluster Insights Fixes: #9294 --- aws/data_source_aws_ecs_cluster.go | 21 +++++++ aws/data_source_aws_ecs_cluster_test.go | 59 +++++++++++++++++++ aws/resource_aws_ecs_cluster.go | 74 +++++++++++++++++++++++- aws/resource_aws_ecs_cluster_test.go | 37 ++++++++++++ website/docs/d/ecs_cluster.html.markdown | 1 + website/docs/r/ecs_cluster.html.markdown | 8 +++ 6 files changed, 198 insertions(+), 2 deletions(-) diff --git a/aws/data_source_aws_ecs_cluster.go b/aws/data_source_aws_ecs_cluster.go index 308bdb9a95a..ab54d2e1cf1 100644 --- a/aws/data_source_aws_ecs_cluster.go +++ b/aws/data_source_aws_ecs_cluster.go @@ -44,6 +44,23 @@ func dataSourceAwsEcsCluster() *schema.Resource { Type: schema.TypeInt, Computed: true, }, + + "setting": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "value": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, }, } } @@ -77,5 +94,9 @@ func dataSourceAwsEcsClusterRead(d *schema.ResourceData, meta interface{}) error d.Set("running_tasks_count", cluster.RunningTasksCount) d.Set("registered_container_instances_count", cluster.RegisteredContainerInstancesCount) + if err := d.Set("setting", flattenEcsSettings(cluster.Settings)); err != nil { + return fmt.Errorf("error setting setting: %s", err) + } + return nil } diff --git a/aws/data_source_aws_ecs_cluster_test.go b/aws/data_source_aws_ecs_cluster_test.go index 53caa633702..f9a99f498b3 100644 --- a/aws/data_source_aws_ecs_cluster_test.go +++ b/aws/data_source_aws_ecs_cluster_test.go @@ -27,6 +27,28 @@ func TestAccAWSEcsDataSource_ecsCluster(t *testing.T) { }) } +func TestAccAWSEcsDataSource_ecsClusterContainerInsights(t *testing.T) { + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckAwsEcsClusterDataSourceConfigContainerInsights, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.aws_ecs_cluster.default", "status", "ACTIVE"), + resource.TestCheckResourceAttr("data.aws_ecs_cluster.default", "pending_tasks_count", "0"), + resource.TestCheckResourceAttr("data.aws_ecs_cluster.default", "running_tasks_count", "0"), + resource.TestCheckResourceAttr("data.aws_ecs_cluster.default", "registered_container_instances_count", "0"), + resource.TestCheckResourceAttrSet("data.aws_ecs_cluster.default", "arn"), + resource.TestCheckResourceAttr("data.aws_ecs_cluster.default", "setting.#", "1"), + resource.TestCheckResourceAttr("data.aws_ecs_cluster.default", "setting.4047805881.name", "containerInsights"), + resource.TestCheckResourceAttr("data.aws_ecs_cluster.default", "setting.4047805881.value", "enabled"), + ), + }, + }, + }) +} + var testAccCheckAwsEcsClusterDataSourceConfig = fmt.Sprintf(` resource "aws_ecs_cluster" "default" { name = "default-%d" @@ -59,3 +81,40 @@ data "aws_ecs_cluster" "default" { cluster_name = "${aws_ecs_cluster.default.name}" } `, acctest.RandInt()) + +var testAccCheckAwsEcsClusterDataSourceConfigContainerInsights = fmt.Sprintf(` +resource "aws_ecs_cluster" "default" { + name = "default-%d" + setting { + name = "containerInsights" + value = "enabled" + } +} + +resource "aws_ecs_task_definition" "mongo" { + family = "mongodb" + container_definitions = <