From 931a38c9ce7f240b361b710fef15e9c805650f5f Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 19 Dec 2023 12:31:05 -0800 Subject: [PATCH] Add region to aws.ecs.cluster + improve defaults (#2862) Also use StringDataPtr where we can Signed-off-by: Tim Smith --- providers/aws/resources/aws.lr | 4 +++- providers/aws/resources/aws.lr.go | 12 ++++++++++++ providers/aws/resources/aws.lr.manifest.yaml | 1 + providers/aws/resources/aws_ecs.go | 5 +++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/providers/aws/resources/aws.lr b/providers/aws/resources/aws.lr index e40e14005f..4fec628402 100644 --- a/providers/aws/resources/aws.lr +++ b/providers/aws/resources/aws.lr @@ -1172,7 +1172,7 @@ aws.ecs { } // Amazon ECS cluster -private aws.ecs.cluster { +private aws.ecs.cluster @defaults("name region status runningTasksCount pendingTasksCount") { // ARN of the ECS cluster arn string // Name of the ECS cluster @@ -1193,6 +1193,8 @@ private aws.ecs.cluster { tasks() []aws.ecs.task // List of AWS ECS container instances containerInstances() []aws.ecs.instance + // The region where the cluster is located + region string } // AWS ECS container instance diff --git a/providers/aws/resources/aws.lr.go b/providers/aws/resources/aws.lr.go index dae9cb321d..b689aa75b3 100644 --- a/providers/aws/resources/aws.lr.go +++ b/providers/aws/resources/aws.lr.go @@ -1986,6 +1986,9 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "aws.ecs.cluster.containerInstances": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAwsEcsCluster).GetContainerInstances()).ToDataRes(types.Array(types.Resource("aws.ecs.instance"))) }, + "aws.ecs.cluster.region": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAwsEcsCluster).GetRegion()).ToDataRes(types.String) + }, "aws.ecs.instance.agentConnected": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAwsEcsInstance).GetAgentConnected()).ToDataRes(types.Bool) }, @@ -5633,6 +5636,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAwsEcsCluster).ContainerInstances, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, + "aws.ecs.cluster.region": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAwsEcsCluster).Region, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "aws.ecs.instance.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAwsEcsInstance).__id, ok = v.Value.(string) return @@ -14339,6 +14346,7 @@ type mqlAwsEcsCluster struct { Status plugin.TValue[string] Tasks plugin.TValue[[]interface{}] ContainerInstances plugin.TValue[[]interface{}] + Region plugin.TValue[string] } // createAwsEcsCluster creates a new instance of this resource @@ -14442,6 +14450,10 @@ func (c *mqlAwsEcsCluster) GetContainerInstances() *plugin.TValue[[]interface{}] }) } +func (c *mqlAwsEcsCluster) GetRegion() *plugin.TValue[string] { + return &c.Region +} + // mqlAwsEcsInstance for the aws.ecs.instance resource type mqlAwsEcsInstance struct { MqlRuntime *plugin.Runtime diff --git a/providers/aws/resources/aws.lr.manifest.yaml b/providers/aws/resources/aws.lr.manifest.yaml index e70398c6c2..7f0fa43465 100755 --- a/providers/aws/resources/aws.lr.manifest.yaml +++ b/providers/aws/resources/aws.lr.manifest.yaml @@ -1233,6 +1233,7 @@ resources: containerInstances: {} name: {} pendingTasksCount: {} + region: {} registeredContainerInstancesCount: {} runningTasksCount: {} status: {} diff --git a/providers/aws/resources/aws_ecs.go b/providers/aws/resources/aws_ecs.go index a631e62163..23d902268f 100644 --- a/providers/aws/resources/aws_ecs.go +++ b/providers/aws/resources/aws_ecs.go @@ -188,13 +188,14 @@ func initAwsEcsCluster(runtime *plugin.Runtime, args map[string]*llx.RawData) (m if err != nil { return nil, nil, err } - args["name"] = llx.StringData(convert.ToString(c.ClusterName)) + args["name"] = llx.StringDataPtr(c.ClusterName) args["tags"] = llx.MapData(ecsTags(c.Tags), types.String) args["runningTasksCount"] = llx.IntData(int64(c.RunningTasksCount)) args["pendingTasksCount"] = llx.IntData(int64(c.PendingTasksCount)) args["registeredContainerInstancesCount"] = llx.IntData(int64(c.RegisteredContainerInstancesCount)) args["configuration"] = llx.MapData(configuration, types.String) - args["status"] = llx.StringData(convert.ToString(c.Status)) + args["status"] = llx.StringDataPtr(c.Status) + args["region"] = llx.StringData(region) return args, nil, nil }