Skip to content

Commit

Permalink
Add support to specify the number of days to transition to inactive s…
Browse files Browse the repository at this point in the history
…torage
  • Loading branch information
berenddeboer committed Apr 4, 2021
1 parent 92f9995 commit 20a95a1
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions plugins/modules/efs.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
- How long the module should wait (in seconds) for desired state before returning. Zero means wait as long as necessary.
default: 0
type: int
transition_to_ia:
description:
- How many days before objects transition to the lower-cost EFS Infrequent Access (IA) storage class. If set to None, any existing lifecyle policy will be removed, and objects will not transition to an IA storage class. If this parameter is absent or left empty, any existing lifecycle policy will not be affected.
default: not set
choices: ['None', '7', '14', '30', '60', '90']
extends_documentation_fragment:
- amazon.aws.aws
Expand Down Expand Up @@ -128,6 +134,24 @@
- subnet_id: subnet-7654fdca
security_groups: [ "sg-4c5d6f7a" ]
- name: Set a lifecycle policy
community.aws.efs:
state: present
name: myTestEFS
transition_to_ia: 7
targets:
- subnet_id: subnet-7654fdca
security_groups: [ "sg-4c5d6f7a" ]
- name: Remove a lifecycle policy
community.aws.efs:
state: present
name: myTestEFS
transition_to_ia: None
targets:
- subnet_id: subnet-7654fdca
security_groups: [ "sg-4c5d6f7a" ]
- name: Deleting EFS
community.aws.efs:
state: absent
Expand Down Expand Up @@ -474,6 +498,27 @@ def update_file_system(self, name, throughput_mode, provisioned_throughput_in_mi
self.module.fail_json_aws(e, msg="Unable to update file system.")
return changed

def update_lifecycle_policy(self, name, transition_to_ia):
"""
Update filesystem with new lifecycle policy.
"""
changed = False
state = self.get_file_system_state(name)
if state in [self.STATE_AVAILABLE, self.STATE_CREATING]:
fs_id = self.get_file_system_id(name)
current_policies = self.connection.describe_lifecycle_configuration(FileSystemId=fs_id)
if transition_to_ia == 'None':
LifecyclePolicies = []
else:
LifecyclePolicies = [{ 'TransitionToIA': 'AFTER_' + transition_to_ia + '_DAYS' }]
if current_policies.get('LifecyclePolicies') != LifecyclePolicies:
response = self.connection.put_lifecycle_configuration(
FileSystemId=fs_id,
LifecyclePolicies = LifecyclePolicies
)
changed = True
return changed

def converge_file_system(self, name, tags, purge_tags, targets, throughput_mode, provisioned_throughput_in_mibps):
"""
Change attributes (mount targets and tags) of filesystem by name
Expand Down Expand Up @@ -695,6 +740,7 @@ def main():
tags=dict(required=False, type="dict", default={}),
targets=dict(required=False, type="list", default=[], elements='dict'),
performance_mode=dict(required=False, type='str', choices=["general_purpose", "max_io"], default="general_purpose"),
transition_to_ia=dict(required=False, choices=["", "None", "7", "14", "30", "60", "90"], default=None),
throughput_mode=dict(required=False, type='str', choices=["bursting", "provisioned"], default=None),
provisioned_throughput_in_mibps=dict(required=False, type='float'),
wait=dict(required=False, type="bool", default=False),
Expand Down Expand Up @@ -722,6 +768,7 @@ def main():
kms_key_id = module.params.get('kms_key_id')
performance_mode = performance_mode_translations[module.params.get('performance_mode')]
purge_tags = module.params.get('purge_tags')
transition_to_ia = module.params.get('transition_to_ia')
throughput_mode = module.params.get('throughput_mode')
provisioned_throughput_in_mibps = module.params.get('provisioned_throughput_in_mibps')
state = str(module.params.get('state')).lower()
Expand All @@ -736,6 +783,8 @@ def main():
changed = connection.update_file_system(name, throughput_mode, provisioned_throughput_in_mibps) or changed
changed = connection.converge_file_system(name=name, tags=tags, purge_tags=purge_tags, targets=targets,
throughput_mode=throughput_mode, provisioned_throughput_in_mibps=provisioned_throughput_in_mibps) or changed
if transition_to_ia:
changed = connection.update_lifecycle_policy(name, transition_to_ia)
result = first_or_default(connection.get_file_systems(CreationToken=name))

elif state == 'absent':
Expand Down

0 comments on commit 20a95a1

Please sign in to comment.