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

Add replace field to copy-instance-tags #7888

Open
wants to merge 61 commits into
base: main
Choose a base branch
from

Conversation

HappyKid117
Copy link

@HappyKid117 HappyKid117 commented Oct 16, 2022

Implemented replace field in copy-instance-tags action as an enhancement. Closes #7544

Description

The action copy-instance-tags copies all the tags mentioned in the policy from an ec2 instance to its ebs volume. If a tag already exists in the ebs volume, it gets replaced. The field replace is introduced to give users more control over this. If its value is false, the policy skips copying existing tags in the ebs volume.

Usage

If the user does not mention this field in the policy, then its default value is set to true, making it a backward-compatible feature.
replace : false : skips the tags that already exist in the ebs volume.
replace : true : replaces the ebs tags with the ec2 tags.

Example

EC2 tags

Lets use this EC2 instance with the given tags and their values for the following examples.

  • Name = ec2-foo
  • Technical:ApplicationID = 1234
  • Technical:ApplicationName = ec2_app
  • Technical:Environment = ec2_env
  • Technical:PlatformOwner = ec2_owner

Example Policy with replace: false

policies:
  - name: ebs-copy-instance-tags
    resource: ebs
    filters:
      - type: value
        key: "Attachments[0].Device"
        value: not-null
    actions:
      - type: copy-instance-tags
        replace: false
        tags:
          - Name
          - Technical:ApplicationID
          - Technical:ApplicationName
          - Technical:Environment
          - Technical:PlatformOwner

Before running the policy

EBS tags

  • Name : ebs-foo
  • Technical:ApplicationID = 6789

After running the policy

EBS tags

  • Name : ebs-foo
  • Technical:ApplicationID = 6789
  • Technical:ApplicationName = ec2_app
  • Technical:Environment = ec2_env
  • Technical:PlatformOwner = ec2_owner

*Notice that the tags Name and Technical:ApplicationName have not been replaced.

Example Policy without replace

policies:
  - name: ebs-copy-instance-tags
    resource: ebs
    filters:
      - type: value
        key: "Attachments[0].Device"
        value: not-null
    actions:
      - type: copy-instance-tags
        tags:
          - Name
          - Technical:ApplicationID
          - Technical:ApplicationName
          - Technical:Environment
          - Technical:PlatformOwner

Before running the policy

EBS tags

  • Name : ebs-foo
  • Technical:ApplicationID = 6789

After running the policy

EBS tags

  • Name = ec2-foo
  • Technical:ApplicationID = 1234
  • Technical:ApplicationName = ec2_app
  • Technical:Environment = ec2_env
  • Technical:PlatformOwner = ec2_owner

*Notice that the tags Name and Technical:ApplicationName have been replaced.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 16, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: HappyKid117 / name: Happy Kid (af17637)

HappyKid117 and others added 28 commits October 16, 2022 17:53
thisisshi and others added 19 commits October 16, 2022 18:21
Copy link
Member

@ajkerrigan ajkerrigan left a comment

Choose a reason for hiding this comment

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

This looks reasonable to me, and using replace feels like a good choice over skip to avoid potential confusion with the skip-missing option from copy-related-tag. Thanks for the contribution, and for making it backward-compatible too 👍

We'll want to make sure checks clear, and add a test for this new behavior before merging.

@linux-foundation-easycla
Copy link

CLA Missing ID CLA Not Signed

@HappyKid117
Copy link
Author

This looks reasonable to me, and using replace feels like a good choice over skip to avoid potential confusion with the skip-missing option from copy-related-tag. Thanks for the contribution, and for making it backward-compatible too +1

We'll want to make sure checks clear, and add a test for this new behavior before merging.

@ajkerrigan 2 Tests have been added to test this behaviour

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

Successfully merging this pull request may close these issues.

Skip Tags if exist when copy EC2 to EBS