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

d/ecs_service add tags #25961

Merged
merged 1 commit into from
Jul 26, 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/25961.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
data-source/aws_ecs_service: Add `tags` attribute
```
7 changes: 7 additions & 0 deletions internal/service/ecs/service_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
)

func DataSourceService() *schema.Resource {
Expand Down Expand Up @@ -43,12 +44,14 @@ func DataSourceService() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"tags": tftags.TagsSchemaComputed(),
},
}
}

func dataSourceServiceRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).ECSConn
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

clusterArn := d.Get("cluster_arn").(string)
serviceName := d.Get("service_name").(string)
Expand Down Expand Up @@ -84,5 +87,9 @@ func dataSourceServiceRead(d *schema.ResourceData, meta interface{}) error {
d.Set("scheduling_strategy", service.SchedulingStrategy)
d.Set("task_definition", service.TaskDefinition)

if err := d.Set("tags", KeyValueTags(service.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %w", err)
}

return nil
}
4 changes: 4 additions & 0 deletions internal/service/ecs/service_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestAccECSServiceDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName, "scheduling_strategy", dataSourceName, "scheduling_strategy"),
resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "service_name"),
resource.TestCheckResourceAttrPair(resourceName, "task_definition", dataSourceName, "task_definition"),
resource.TestCheckResourceAttrPair(resourceName, "tags", dataSourceName, "tags"),
),
},
},
Expand Down Expand Up @@ -63,6 +64,9 @@ resource "aws_ecs_service" "test" {
cluster = aws_ecs_cluster.test.id
task_definition = aws_ecs_task_definition.test.arn
desired_count = 1
tags = {
Name = %[1]q
}
}

data "aws_ecs_service" "test" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/ecs_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ In addition to all arguments above, the following attributes are exported:
* `launch_type` - The launch type for the ECS Service
* `scheduling_strategy` - The scheduling strategy for the ECS Service
* `task_definition` - The family for the latest ACTIVE revision
* `tags` - Resource tags.