ec2_vpc - More dry running in check mode.
This commit is contained in:
parent
9068bde560
commit
b76f9a7eca
1 changed files with 14 additions and 19 deletions
|
@ -171,7 +171,7 @@ def get_resource_tags(vpc_conn, resource_id):
|
||||||
vpc_conn.get_all_tags(filters={'resource-id': resource_id})}
|
vpc_conn.get_all_tags(filters={'resource-id': resource_id})}
|
||||||
|
|
||||||
|
|
||||||
def ensure_tags(vpc_conn, resource_id, tags, add_only, dry_run):
|
def ensure_tags(vpc_conn, resource_id, tags, add_only, check_mode):
|
||||||
try:
|
try:
|
||||||
cur_tags = get_resource_tags(vpc_conn, resource_id)
|
cur_tags = get_resource_tags(vpc_conn, resource_id)
|
||||||
if tags == cur_tags:
|
if tags == cur_tags:
|
||||||
|
@ -179,11 +179,11 @@ def ensure_tags(vpc_conn, resource_id, tags, add_only, dry_run):
|
||||||
|
|
||||||
to_delete = {k: cur_tags[k] for k in cur_tags if k not in tags}
|
to_delete = {k: cur_tags[k] for k in cur_tags if k not in tags}
|
||||||
if to_delete and not add_only:
|
if to_delete and not add_only:
|
||||||
vpc_conn.delete_tags(resource_id, to_delete, dry_run=dry_run)
|
vpc_conn.delete_tags(resource_id, to_delete, dry_run=check_mode)
|
||||||
|
|
||||||
to_add = {k: tags[k] for k in tags if k not in cur_tags}
|
to_add = {k: tags[k] for k in tags if k not in cur_tags}
|
||||||
if to_add:
|
if to_add:
|
||||||
vpc_conn.create_tags(resource_id, to_add, dry_run=dry_run)
|
vpc_conn.create_tags(resource_id, to_add, dry_run=check_mode)
|
||||||
|
|
||||||
latest_tags = get_resource_tags(vpc_conn, resource_id)
|
latest_tags = get_resource_tags(vpc_conn, resource_id)
|
||||||
return {'changed': True, 'tags': latest_tags}
|
return {'changed': True, 'tags': latest_tags}
|
||||||
|
@ -252,17 +252,17 @@ def ensure_routes(vpc_conn, route_table, route_specs, check_mode):
|
||||||
if r.gateway_id != 'local']
|
if r.gateway_id != 'local']
|
||||||
|
|
||||||
changed = routes_to_delete or route_specs_to_create
|
changed = routes_to_delete or route_specs_to_create
|
||||||
if check_mode and changed:
|
if changed:
|
||||||
return {'changed': True}
|
|
||||||
elif changed:
|
|
||||||
for route_spec in route_specs_to_create:
|
for route_spec in route_specs_to_create:
|
||||||
vpc_conn.create_route(route_table.id, **route_spec)
|
vpc_conn.create_route(route_table.id,
|
||||||
|
dry_run=check_mode,
|
||||||
|
**route_spec)
|
||||||
|
|
||||||
for route in routes_to_delete:
|
for route in routes_to_delete:
|
||||||
vpc_conn.delete_route(route_table.id, route.destination_cidr_block)
|
vpc_conn.delete_route(route_table.id,
|
||||||
return {'changed': True}
|
route.destination_cidr_block,
|
||||||
else:
|
dry_run=check_mode)
|
||||||
return {'changed': False}
|
return {'changed': changed}
|
||||||
|
|
||||||
|
|
||||||
def get_subnet_by_cidr(vpc_conn, vpc_id, cidr):
|
def get_subnet_by_cidr(vpc_conn, vpc_id, cidr):
|
||||||
|
@ -323,10 +323,8 @@ def ensure_subnet_associations(vpc_conn, vpc_id, route_table, subnets,
|
||||||
if a_id not in new_association_ids]
|
if a_id not in new_association_ids]
|
||||||
|
|
||||||
for a_id in to_delete:
|
for a_id in to_delete:
|
||||||
if check_mode:
|
|
||||||
return {'changed': True}
|
|
||||||
changed = True
|
changed = True
|
||||||
vpc_conn.disassociate_route_table(a_id)
|
vpc_conn.disassociate_route_table(a_id, dry_run=check_mode)
|
||||||
|
|
||||||
return {'changed': changed}
|
return {'changed': changed}
|
||||||
|
|
||||||
|
@ -344,10 +342,7 @@ def ensure_route_table_absent(vpc_conn, vpc_id, route_table_id, resource_tags,
|
||||||
if route_table is None:
|
if route_table is None:
|
||||||
return {'changed': False}
|
return {'changed': False}
|
||||||
|
|
||||||
if check_mode:
|
vpc_conn.delete_route_table(route_table.id, dry_run=check_mode)
|
||||||
return {'changed': True}
|
|
||||||
|
|
||||||
vpc_conn.delete_route_table(route_table.id)
|
|
||||||
return {'changed': True}
|
return {'changed': True}
|
||||||
|
|
||||||
|
|
||||||
|
@ -378,7 +373,7 @@ def ensure_route_table_present(vpc_conn, vpc_id, route_table_id, resource_tags,
|
||||||
|
|
||||||
if not tags_valid and resource_tags is not None:
|
if not tags_valid and resource_tags is not None:
|
||||||
result = ensure_tags(vpc_conn, route_table.id, resource_tags,
|
result = ensure_tags(vpc_conn, route_table.id, resource_tags,
|
||||||
add_only=True, dry_run=check_mode)
|
add_only=True, check_mode=check_mode)
|
||||||
changed = changed or result['changed']
|
changed = changed or result['changed']
|
||||||
|
|
||||||
if routes is not None:
|
if routes is not None:
|
||||||
|
|
Loading…
Reference in a new issue