Skip to content

Support for Tags (tagging) for ECS Service and Task Creation - #2466

Open
elliotechne wants to merge 6 commits into
ansible-collections:mainfrom
elliotechne:bug/2446
Open

Support for Tags (tagging) for ECS Service and Task Creation#2466
elliotechne wants to merge 6 commits into
ansible-collections:mainfrom
elliotechne:bug/2446

Conversation

@elliotechne

@elliotechne elliotechne commented Jun 28, 2026

Copy link
Copy Markdown
SUMMARY

fixes: #2446

 - name: Demo ECS tagging support
  hosts: localhost
  gather_facts: false
  collections:
    - community.aws

  vars:
    cluster_name: demo-cluster
    service_name: demo-service
    task_family: demo-task

  tasks:
    - name: Create ECS cluster with tags
      community.aws.ecs_cluster:
        name: "{{ cluster_name }}"
        state: present
        tags:
          Environment: production
          Team: backend
      register: cluster_result 

    - name: Show cluster tags
      ansible.builtin.debug:
        var: cluster_result.cluster.tags

    - name: Register task definition with tags
      community.aws.ecs_taskdefinition:
        family: "{{ task_family }}"
        containers:
          - name: nginx
            essential: true
            image: "nginx:latest"
            memory: 256
            portMappings:
              - containerPort: 80
                hostPort: 80
        network_mode: bridge
        state: present
        tags:
          Environment: production
          Team: backend
      register: taskdef_result

    - name: Show task definition ARN
      ansible.builtin.debug:
        var: taskdef_result.taskdefinition.taskDefinitionArn

    - name: Create ECS service with tags
      community.aws.ecs_service:
        name: "{{ service_name }}"
        cluster: "{{ cluster_name }}"
        task_definition: "{{ task_family }}"
        desired_count: 0
        state: present
        tags:
          Environment: production
          Team: backend
      register: service_result

    - name: Show service tags
      ansible.builtin.debug:
        var: service_result.service.tags

    - name: Update cluster tags (purge old, set new)
      community.aws.ecs_cluster:
        name: "{{ cluster_name }}"
        state: present
        tags:
          Environment: staging
        purge_tags: true
      register: cluster_updated

    - name: Show updated cluster tags
      ansible.builtin.debug:
        var: cluster_updated.cluster.tags

    - name: Update service tags
      community.aws.ecs_service:
        name: "{{ service_name }}"
        cluster: "{{ cluster_name }}"
        task_definition: "{{ task_family }}"
        desired_count: 0
        state: present
        tags:
          Environment: staging
          CostCenter: "12345"
        purge_tags: true
      register: service_updated

    - name: Confirm service changed
      ansible.builtin.debug:
        var: service_updated.changed

    - name: Delete service
      community.aws.ecs_service:
        name: "{{ service_name }}"
        cluster: "{{ cluster_name }}"
        state: absent
        force_deletion: true

    - name: Delete cluster
      community.aws.ecs_cluster:
        name: "{{ cluster_name }}"
        state: absent 
ISSUE TYPE
  • Bugfix Pull Request
  • Docs Pull Request
COMPONENT NAME

ecs_tags

ADDITIONAL INFORMATION

Assisted-by: Sonnet 4.6 · Claude Pro

elliotechne and others added 3 commits June 28, 2026 15:07
…d ecs_taskdefinition modules

- ecs_cluster: tags on create/update via tag_resource/untag_resource; describe_cluster includes TAGS
- ecs_service: adds purge_tags, removes fail_json blocking tag updates, reconciles tags independently of update_service
- ecs_taskdefinition: tags on registration; in-place tag reconciliation for existing revisions via list_tags_for_resource

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nition tagging

Covers tags on create, idempotency, tag updates, purge_tags, and in-place
tag reconciliation for task definitions without registering a new revision.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…uard

- ecs_tag/main.yml: update service tag test to expect success now that tag
  updates on existing services are supported (removes the old fail assertion)
- 99_terminate_everything.yml: guard ecs_task_definition_absent_with_arn
  teardown with `when: ... is defined` to survive partial test failures

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 28, 2026

Copy link
Copy Markdown

Docs Build 📝

Thank you for contribution!✨

The docsite for this PR is available for download as an artifact from this run:
https://github.com/ansible-collections/community.aws/actions/runs/28372420137

You can compare to the docs for the main branch here:
https://ansible-collections.github.io/community.aws/branch/main

File changes:

  • M collections/community/aws/ecs_cluster_module.html
  • M collections/community/aws/ecs_service_module.html
  • M collections/community/aws/ecs_taskdefinition_module.html
Click to see the diff comparison.

NOTE: only file modifications are shown here. New and deleted files are excluded.
See the file list and check the published docs to see those files.

diff --git a/home/runner/work/community.aws/community.aws/docsbuild/base/collections/community/aws/ecs_cluster_module.html b/home/runner/work/community.aws/community.aws/docsbuild/head/collections/community/aws/ecs_cluster_module.html
index 3fa61fb..8f80ba1 100644
--- a/home/runner/work/community.aws/community.aws/docsbuild/base/collections/community/aws/ecs_cluster_module.html
+++ b/home/runner/work/community.aws/community.aws/docsbuild/head/collections/community/aws/ecs_cluster_module.html
@@ -310,6 +310,20 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-c
 </div></td>
 </tr>
 <tr class="row-even"><td><div class="ansible-option-cell">
+<div class="ansibleOptionAnchor" id="parameter-purge_tags"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-cluster-module-parameter-purge-tags"><strong>purge_tags</strong></p>
+<a class="ansibleOptionLink" href="#parameter-purge_tags" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">boolean</span></p>
+<p><em class="ansible-option-versionadded">added in community.aws 12.0.0</em></p>
+</div></td>
+<td><div class="ansible-option-cell"><p>If <em>purge_tags=true</em> and <em>tags</em> is set, existing tags not in <em>tags</em> will be removed from the cluster.</p>
+<p>If <em>tags</em> is not set, tags will not be modified, even if <em>purge_tags=true</em>.</p>
+<p class="ansible-option-line"><strong class="ansible-option-choices">Choices:</strong></p>
+<ul class="simple">
+<li><p><code class="ansible-option-choices-entry docutils literal notranslate"><span class="pre">false</span></code></p></li>
+<li><p><code class="ansible-option-default-bold docutils literal notranslate"><strong><span class="pre">true</span></strong></code> <span class="ansible-option-choices-default-mark">← (default)</span></p></li>
+</ul>
+</div></td>
+</tr>
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-region"></div>
 <div class="ansibleOptionAnchor" id="parameter-aws_region"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-cluster-module-parameter-region"><span id="ansible-collections-community-aws-ecs-cluster-module-parameter-aws-region"></span><strong>region</strong></p>
 <a class="ansibleOptionLink" href="#parameter-region" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-aliases">aliases: aws_region</span></p>
@@ -321,7 +335,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-c
 <p>See the Amazon AWS documentation for more information <a class="reference external" href="http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region">http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region</a>.</p>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-repeat"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-cluster-module-parameter-repeat"><strong>repeat</strong></p>
 <a class="ansibleOptionLink" href="#parameter-repeat" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">integer</span></p>
 </div></td>
@@ -329,7 +343,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-c
 <p class="ansible-option-line"><strong class="ansible-option-default-bold">Default:</strong> <code class="ansible-option-default docutils literal notranslate"><span class="pre">10</span></code></p>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-secret_key"></div>
 <div class="ansibleOptionAnchor" id="parameter-aws_secret_access_key"></div>
 <div class="ansibleOptionAnchor" id="parameter-aws_secret_key"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-cluster-module-parameter-secret-key"><span id="ansible-collections-community-aws-ecs-cluster-module-parameter-aws-secret-key"></span><span id="ansible-collections-community-aws-ecs-cluster-module-parameter-aws-secret-access-key"></span><strong>secret_key</strong></p>
@@ -343,7 +357,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-c
 <p>The <em>aws_secret_access_key</em> alias was added in release 5.1.0 for consistency with the AWS botocore SDK.</p>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-session_token"></div>
 <div class="ansibleOptionAnchor" id="parameter-aws_session_token"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-cluster-module-parameter-session-token"><span id="ansible-collections-community-aws-ecs-cluster-module-parameter-aws-session-token"></span><strong>session_token</strong></p>
 <a class="ansibleOptionLink" href="#parameter-session_token" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-aliases">aliases: aws_session_token</span></p>
@@ -355,7 +369,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-c
 <p>The <em>session_token</em> and <em>profile</em> options are mutually exclusive.</p>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-state"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-cluster-module-parameter-state"><strong>state</strong></p>
 <a class="ansibleOptionLink" href="#parameter-state" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span> / <span class="ansible-option-required">required</span></p>
 </div></td>
@@ -368,6 +382,15 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-c
 </ul>
 </div></td>
 </tr>
+<tr class="row-even"><td><div class="ansible-option-cell">
+<div class="ansibleOptionAnchor" id="parameter-tags"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-cluster-module-parameter-tags"><strong>tags</strong></p>
+<a class="ansibleOptionLink" href="#parameter-tags" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">dictionary</span></p>
+<p><em class="ansible-option-versionadded">added in community.aws 12.0.0</em></p>
+</div></td>
+<td><div class="ansible-option-cell"><p>A dictionary of tags to apply to the ECS cluster.</p>
+<p>If <em>tags</em> is not set, tags will not be modified.</p>
+</div></td>
+</tr>
 <tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-validate_certs"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-cluster-module-parameter-validate-certs"><strong>validate_certs</strong></p>
 <a class="ansibleOptionLink" href="#parameter-validate_certs" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">boolean</span></p>
@@ -420,6 +443,14 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-c
 <span class="w">        </span><span class="nt">weight</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">100</span>
 <span class="w">    </span><span class="nt">purge_capacity_providers</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">true</span>
 
+<span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">Cluster creation with tags</span>
+<span class="w">  </span><span class="nt">community.aws.ecs_cluster</span><span class="p">:</span>
+<span class="w">    </span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">my-cluster</span>
+<span class="w">    </span><span class="nt">state</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">present</span>
+<span class="w">    </span><span class="nt">tags</span><span class="p">:</span>
+<span class="w">      </span><span class="nt">Environment</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">production</span>
+<span class="w">      </span><span class="nt">Team</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">backend</span>
+
 <span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">Cluster deletion</span>
 <span class="w">  </span><span class="nt">community.aws.ecs_cluster</span><span class="p">:</span>
 <span class="w">    </span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">default</span>
@@ -522,6 +553,15 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-c
 <p class="ansible-option-line ansible-option-sample"><strong class="ansible-option-sample-bold">Sample:</strong> <code class="ansible-option-sample docutils literal notranslate"><span class="pre">&quot;ACTIVE&quot;</span></code></p>
 </div></td>
 </tr>
+<tr class="row-odd"><td><div class="ansible-option-cell">
+<div class="ansibleOptionAnchor" id="return-tags"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-cluster-module-return-tags"><strong>tags</strong></p>
+<a class="ansibleOptionLink" href="#return-tags" title="Permalink to this return value"></a><p class="ansible-option-type-line"><span class="ansible-option-type">dictionary</span></p>
+<p><em class="ansible-option-versionadded">added in community.aws 12.0.0</em></p>
+</div></td>
+<td><div class="ansible-option-cell"><p>The tags associated with the cluster.</p>
+<p class="ansible-option-line"><strong class="ansible-option-returned-bold">Returned:</strong> always</p>
+</div></td>
+</tr>
 </tbody>
 </table>
 <section id="authors">
diff --git a/home/runner/work/community.aws/community.aws/docsbuild/base/collections/community/aws/ecs_service_module.html b/home/runner/work/community.aws/community.aws/docsbuild/head/collections/community/aws/ecs_service_module.html
index efc9434..a223bb0 100644
--- a/home/runner/work/community.aws/community.aws/docsbuild/base/collections/community/aws/ecs_service_module.html
+++ b/home/runner/work/community.aws/community.aws/docsbuild/head/collections/community/aws/ecs_service_module.html
@@ -588,6 +588,21 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-s
 </div></td>
 </tr>
 <tr class="row-odd"><td><div class="ansible-option-cell">
+<div class="ansibleOptionAnchor" id="parameter-purge_tags"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-service-module-parameter-purge-tags"><strong>purge_tags</strong></p>
+<a class="ansibleOptionLink" href="#parameter-purge_tags" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">boolean</span></p>
+<p><em class="ansible-option-versionadded">added in community.aws 12.0.0</em></p>
+</div></td>
+<td><div class="ansible-option-cell"><p>If <em>purge_tags=true</em> and <em>tags</em> is set, existing tags not in <em>tags</em> will be removed from the service.</p>
+<p>If <em>tags</em> is not set, tags will not be modified, even if <em>purge_tags=true</em>.</p>
+<p>This option only takes effect when updating an existing service; tags are fully controlled at creation time.</p>
+<p class="ansible-option-line"><strong class="ansible-option-choices">Choices:</strong></p>
+<ul class="simple">
+<li><p><code class="ansible-option-default-bold docutils literal notranslate"><strong><span class="pre">false</span></strong></code> <span class="ansible-option-choices-default-mark">← (default)</span></p></li>
+<li><p><code class="ansible-option-choices-entry docutils literal notranslate"><span class="pre">true</span></code></p></li>
+</ul>
+</div></td>
+</tr>
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-region"></div>
 <div class="ansibleOptionAnchor" id="parameter-aws_region"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-service-module-parameter-region"><span id="ansible-collections-community-aws-ecs-service-module-parameter-aws-region"></span><strong>region</strong></p>
 <a class="ansibleOptionLink" href="#parameter-region" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-aliases">aliases: aws_region</span></p>
@@ -599,7 +614,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-s
 <p>See the Amazon AWS documentation for more information <a class="reference external" href="http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region">http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region</a>.</p>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-repeat"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-service-module-parameter-repeat"><strong>repeat</strong></p>
 <a class="ansibleOptionLink" href="#parameter-repeat" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">integer</span></p>
 </div></td>
@@ -607,7 +622,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-s
 <p class="ansible-option-line"><strong class="ansible-option-default-bold">Default:</strong> <code class="ansible-option-default docutils literal notranslate"><span class="pre">10</span></code></p>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-role"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-service-module-parameter-role"><strong>role</strong></p>
 <a class="ansibleOptionLink" href="#parameter-role" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
@@ -616,7 +631,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-s
 <p class="ansible-option-line"><strong class="ansible-option-default-bold">Default:</strong> <code class="ansible-option-default docutils literal notranslate"><span class="pre">&quot;&quot;</span></code></p>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-scheduling_strategy"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-service-module-parameter-scheduling-strategy"><strong>scheduling_strategy</strong></p>
 <a class="ansibleOptionLink" href="#parameter-scheduling_strategy" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
@@ -629,7 +644,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-s
 </ul>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-secret_key"></div>
 <div class="ansibleOptionAnchor" id="parameter-aws_secret_access_key"></div>
 <div class="ansibleOptionAnchor" id="parameter-aws_secret_key"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-service-module-parameter-secret-key"><span id="ansible-collections-community-aws-ecs-service-module-parameter-aws-secret-key"></span><span id="ansible-collections-community-aws-ecs-service-module-parameter-aws-secret-access-key"></span><strong>secret_key</strong></p>
@@ -643,7 +658,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-s
 <p>The <em>aws_secret_access_key</em> alias was added in release 5.1.0 for consistency with the AWS botocore SDK.</p>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-service_registries"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-service-module-parameter-service-registries"><strong>service_registries</strong></p>
 <a class="ansibleOptionLink" href="#parameter-service_registries" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">list</span> / <span class="ansible-option-elements">elements=dictionary</span></p>
 </div></td>
@@ -651,28 +666,28 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-s
 <p class="ansible-option-line"><strong class="ansible-option-default-bold">Default:</strong> <code class="ansible-option-default docutils literal notranslate"><span class="pre">[]</span></code></p>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-indent"></div><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-indent"></div><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-service_registries/arn"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-service-module-parameter-service-registries-arn"><strong>arn</strong></p>
 <a class="ansibleOptionLink" href="#parameter-service_registries/arn" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
 <td><div class="ansible-option-indent-desc"></div><div class="ansible-option-cell"><p>Service discovery registry ARN.</p>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-indent"></div><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-indent"></div><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-service_registries/container_name"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-service-module-parameter-service-registries-container-name"><strong>container_name</strong></p>
 <a class="ansibleOptionLink" href="#parameter-service_registries/container_name" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
 <td><div class="ansible-option-indent-desc"></div><div class="ansible-option-cell"><p>Container name for service discovery registration.</p>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-indent"></div><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-indent"></div><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-service_registries/container_port"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-service-module-parameter-service-registries-container-port"><strong>container_port</strong></p>
 <a class="ansibleOptionLink" href="#parameter-service_registries/container_port" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">integer</span></p>
 </div></td>
 <td><div class="ansible-option-indent-desc"></div><div class="ansible-option-cell"><p>Container port for service discovery registration.</p>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-session_token"></div>
 <div class="ansibleOptionAnchor" id="parameter-aws_session_token"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-service-module-parameter-session-token"><span id="ansible-collections-community-aws-ecs-service-module-parameter-aws-session-token"></span><strong>session_token</strong></p>
 <a class="ansibleOptionLink" href="#parameter-session_token" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-aliases">aliases: aws_session_token</span></p>
@@ -684,7 +699,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-s
 <p>The <em>session_token</em> and <em>profile</em> options are mutually exclusive.</p>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-state"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-service-module-parameter-state"><strong>state</strong></p>
 <a class="ansibleOptionLink" href="#parameter-state" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span> / <span class="ansible-option-required">required</span></p>
 </div></td>
@@ -697,7 +712,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-s
 </ul>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-tags"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-service-module-parameter-tags"><strong>tags</strong></p>
 <a class="ansibleOptionLink" href="#parameter-tags" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">dictionary</span></p>
 <p><em class="ansible-option-versionadded">added in community.aws 4.1.0</em></p>
@@ -705,7 +720,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-s
 <td><div class="ansible-option-cell"><p>A dictionary of tags to add or remove from the resource.</p>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-task_definition"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-service-module-parameter-task-definition"><strong>task_definition</strong></p>
 <a class="ansibleOptionLink" href="#parameter-task_definition" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
@@ -714,7 +729,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-s
 <p>This parameter is ignored when updating a service with a <code class="docutils literal notranslate"><span class="pre">CODE_DEPLOY</span></code> deployment controller in which case the task definition is managed by Code Pipeline and cannot be updated.</p>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-validate_certs"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-service-module-parameter-validate-certs"><strong>validate_certs</strong></p>
 <a class="ansibleOptionLink" href="#parameter-validate_certs" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">boolean</span></p>
 </div></td>
@@ -727,7 +742,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-s
 </ul>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-wait"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-service-module-parameter-wait"><strong>wait</strong></p>
 <a class="ansibleOptionLink" href="#parameter-wait" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">boolean</span></p>
 <p><em class="ansible-option-versionadded">added in community.aws 4.1.0</em></p>
diff --git a/home/runner/work/community.aws/community.aws/docsbuild/base/collections/community/aws/ecs_taskdefinition_module.html b/home/runner/work/community.aws/community.aws/docsbuild/head/collections/community/aws/ecs_taskdefinition_module.html
index d1920eb..3fe84ae 100644
--- a/home/runner/work/community.aws/community.aws/docsbuild/base/collections/community/aws/ecs_taskdefinition_module.html
+++ b/home/runner/work/community.aws/community.aws/docsbuild/head/collections/community/aws/ecs_taskdefinition_module.html
@@ -1241,6 +1241,21 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-t
 </div></td>
 </tr>
 <tr class="row-even"><td><div class="ansible-option-cell">
+<div class="ansibleOptionAnchor" id="parameter-purge_tags"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-taskdefinition-module-parameter-purge-tags"><strong>purge_tags</strong></p>
+<a class="ansibleOptionLink" href="#parameter-purge_tags" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">boolean</span></p>
+<p><em class="ansible-option-versionadded">added in community.aws 12.0.0</em></p>
+</div></td>
+<td><div class="ansible-option-cell"><p>If <em>purge_tags=true</em> and <em>tags</em> is set, existing tags not in <em>tags</em> will be removed from the task definition.</p>
+<p>Has no effect when registering a new task definition revision (tags at registration fully replace any prior state).</p>
+<p>If <em>tags</em> is not set, tags will not be modified, even if <em>purge_tags=true</em>.</p>
+<p class="ansible-option-line"><strong class="ansible-option-choices">Choices:</strong></p>
+<ul class="simple">
+<li><p><code class="ansible-option-default-bold docutils literal notranslate"><strong><span class="pre">false</span></strong></code> <span class="ansible-option-choices-default-mark">← (default)</span></p></li>
+<li><p><code class="ansible-option-choices-entry docutils literal notranslate"><span class="pre">true</span></code></p></li>
+</ul>
+</div></td>
+</tr>
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-region"></div>
 <div class="ansibleOptionAnchor" id="parameter-aws_region"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-taskdefinition-module-parameter-region"><span id="ansible-collections-community-aws-ecs-taskdefinition-module-parameter-aws-region"></span><strong>region</strong></p>
 <a class="ansibleOptionLink" href="#parameter-region" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-aliases">aliases: aws_region</span></p>
@@ -1252,14 +1267,14 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-t
 <p>See the Amazon AWS documentation for more information <a class="reference external" href="http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region">http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region</a>.</p>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-revision"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-taskdefinition-module-parameter-revision"><strong>revision</strong></p>
 <a class="ansibleOptionLink" href="#parameter-revision" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">integer</span></p>
 </div></td>
 <td><div class="ansible-option-cell"><p>A revision number for the task definition.</p>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-runtime_platform"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-taskdefinition-module-parameter-runtime-platform"><strong>runtime_platform</strong></p>
 <a class="ansibleOptionLink" href="#parameter-runtime_platform" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">dictionary</span></p>
 <p><em class="ansible-option-versionadded">added in community.aws 6.4.0</em></p>
@@ -1268,7 +1283,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-t
 <p class="ansible-option-line"><strong class="ansible-option-default-bold">Default:</strong> <code class="ansible-option-default docutils literal notranslate"><span class="pre">{&quot;cpuArchitecture&quot;:</span> <span class="pre">&quot;X86_64&quot;,</span> <span class="pre">&quot;operatingSystemFamily&quot;:</span> <span class="pre">&quot;LINUX&quot;}</span></code></p>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-indent"></div><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-indent"></div><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-runtime_platform/cpuArchitecture"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-taskdefinition-module-parameter-runtime-platform-cpuarchitecture"><strong>cpuArchitecture</strong></p>
 <a class="ansibleOptionLink" href="#parameter-runtime_platform/cpuArchitecture" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
@@ -1280,7 +1295,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-t
 </ul>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-indent"></div><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-indent"></div><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-runtime_platform/operatingSystemFamily"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-taskdefinition-module-parameter-runtime-platform-operatingsystemfamily"><strong>operatingSystemFamily</strong></p>
 <a class="ansibleOptionLink" href="#parameter-runtime_platform/operatingSystemFamily" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
@@ -1295,7 +1310,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-t
 </ul>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-secret_key"></div>
 <div class="ansibleOptionAnchor" id="parameter-aws_secret_access_key"></div>
 <div class="ansibleOptionAnchor" id="parameter-aws_secret_key"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-taskdefinition-module-parameter-secret-key"><span id="ansible-collections-community-aws-ecs-taskdefinition-module-parameter-aws-secret-key"></span><span id="ansible-collections-community-aws-ecs-taskdefinition-module-parameter-aws-secret-access-key"></span><strong>secret_key</strong></p>
@@ -1309,7 +1324,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-t
 <p>The <em>aws_secret_access_key</em> alias was added in release 5.1.0 for consistency with the AWS botocore SDK.</p>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-session_token"></div>
 <div class="ansibleOptionAnchor" id="parameter-aws_session_token"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-taskdefinition-module-parameter-session-token"><span id="ansible-collections-community-aws-ecs-taskdefinition-module-parameter-aws-session-token"></span><strong>session_token</strong></p>
 <a class="ansibleOptionLink" href="#parameter-session_token" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-aliases">aliases: aws_session_token</span></p>
@@ -1321,7 +1336,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-t
 <p>The <em>session_token</em> and <em>profile</em> options are mutually exclusive.</p>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-state"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-taskdefinition-module-parameter-state"><strong>state</strong></p>
 <a class="ansibleOptionLink" href="#parameter-state" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span> / <span class="ansible-option-required">required</span></p>
 </div></td>
@@ -1333,6 +1348,17 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-t
 </ul>
 </div></td>
 </tr>
+<tr class="row-odd"><td><div class="ansible-option-cell">
+<div class="ansibleOptionAnchor" id="parameter-tags"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-taskdefinition-module-parameter-tags"><strong>tags</strong></p>
+<a class="ansibleOptionLink" href="#parameter-tags" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">dictionary</span></p>
+<p><em class="ansible-option-versionadded">added in community.aws 12.0.0</em></p>
+</div></td>
+<td><div class="ansible-option-cell"><p>A dictionary of tags to apply to the task definition.</p>
+<p>When registering a new task definition, tags are applied at registration time.</p>
+<p>When an existing task definition is found (no new revision needed), tags are updated in place without creating a new revision.</p>
+<p>If <em>tags</em> is not set, tags will not be modified.</p>
+</div></td>
+</tr>
 <tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-task_role_arn"></div><p class="ansible-option-title" id="ansible-collections-community-aws-ecs-taskdefinition-module-parameter-task-role-arn"><strong>task_role_arn</strong></p>
 <a class="ansibleOptionLink" href="#parameter-task_role_arn" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
@@ -1517,6 +1543,23 @@ see <a class="reference internal" href="#ansible-collections-community-aws-ecs-t
 <span class="w">          </span><span class="nt">startPeriod</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">15</span>
 <span class="w">          </span><span class="nt">timeout</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">15</span>
 <span class="w">    </span><span class="nt">state</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">present</span>
+
+<span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">Create task definition with tags</span>
+<span class="w">  </span><span class="nt">community.aws.ecs_taskdefinition</span><span class="p">:</span>
+<span class="w">    </span><span class="nt">family</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">nginx</span>
+<span class="w">    </span><span class="nt">containers</span><span class="p">:</span>
+<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">nginx</span>
+<span class="w">        </span><span class="nt">essential</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">true</span>
+<span class="w">        </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;nginx&quot;</span>
+<span class="w">        </span><span class="nt">portMappings</span><span class="p">:</span>
+<span class="w">          </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">containerPort</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">8080</span>
+<span class="w">            </span><span class="nt">hostPort</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">8080</span>
+<span class="w">        </span><span class="nt">cpu</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">512</span>
+<span class="w">        </span><span class="nt">memory</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">1024</span>
+<span class="w">    </span><span class="nt">state</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">present</span>
+<span class="w">    </span><span class="nt">tags</span><span class="p">:</span>
+<span class="w">      </span><span class="nt">Environment</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">production</span>
+<span class="w">      </span><span class="nt">Team</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">backend</span>
 </pre></div>
 </div>
 </section>

@centosinfra-prod-github-app

Copy link
Copy Markdown
Contributor

@tremble tremble changed the title Bug/2446 Support for Tags (tagging) for ECS Service and Task Creation Jun 29, 2026

@tremble tremble left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to submit this PR.

A couple of comments.

  1. purge_tags should default to True
  2. The tag management logic should probably be split into dedicated functions.

Comment thread plugins/modules/ecs_cluster.py Outdated
Comment thread plugins/modules/ecs_cluster.py
elliotechne and others added 3 commits June 29, 2026 11:30
…n tags support

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
After calling tag_resource/untag_resource the results["cluster"] dict
still pointed at the pre-change describe response, so tag-value
assertions in the integration tests always saw the old (stale) tags.
Re-describe the cluster inside the tag-change block so the returned
dict reflects the applied state.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace the nested tag-reconciliation if statements with a standalone
ensure_tags() function. Change purge_tags default from false to true,
consistent with purge_capacity_providers behaviour.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@centosinfra-prod-github-app

Copy link
Copy Markdown
Contributor

@elliotechne

Copy link
Copy Markdown
Author

@tremble Updated. Thank you for the review!

@centosinfra-prod-github-app

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for Tags (tagging) for ECS Service and Task Creation

2 participants