Skip to content

Commit 3096a37

Browse files
authored
Update and prepare for 5.0.0 release (#20)
* Remove use of six * Fix typo * Code modernization * Add __future__ imports * Remove Python 2 compat * Remove amazon.aws dependency * Breaking Change - Modules no longer accept connection details as module arguments. Standard boto3 environment variables and configuration files must be used instead. This was done to simplify the codebase and ease upgrades. * The collection is no longer dependent on amazon.aws, making it easier to update each one independently. * Update distlib requirement * Remove action_group definition Update integration tests to use boto3 environment variables. * Test against ansible-core 2.18 * Fix pylint issue * Update amazon.aws version used in integration tests * Avoid static analysis issue in PyCharm * Add missing type annotations * Update to version 5.0.0
1 parent 90486a6 commit 3096a37

File tree

29 files changed

+263
-456
lines changed

29 files changed

+263
-456
lines changed

galaxy.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace: mattclay
99
name: aws
1010

1111
# The version of the collection. Must be compatible with semantic versioning
12-
version: 4.1.0
12+
version: 5.0.0
1313

1414
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
1515
readme: README.md
@@ -40,13 +40,6 @@ tags:
4040
- aws
4141
- lambda
4242

43-
# Collections that this collection requires to be installed for it to be usable. The key of the dict is the
44-
# collection label 'namespace.name'. The value is a version range
45-
# L(specifiers,https://python-semanticversion.readthedocs.io/en/latest/#requirement-specification). Multiple version
46-
# range specifiers can be set and are separated by ','
47-
dependencies:
48-
amazon.aws: '>=7.0.0,<8.0.0'
49-
5043
# The URL of the originating SCM repository
5144
repository: https://github.com/mattclay/ansible-collection-aws
5245

meta/runtime.yml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1 @@
11
requires_ansible: '>=2.11'
2-
action_groups:
3-
common:
4-
# this collection
5-
- apigateway
6-
- aws_account_facts
7-
- aws_availability_zone_facts
8-
- cloudwatch_event
9-
- lambda
10-
- lambda_alias
11-
- lambda_layer
12-
- lambda_package
13-
- lambda_policy
14-
- sqs_event
15-
- sqs_fifo_queue
16-
# external collections
17-
- amazon.aws.iam_role

plugins/filter/dictfilter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# Copyright (C) 2016 Matt Clay <[email protected]>
22
# GNU General Public License v3.0+ (see LICENSE.md or https://www.gnu.org/licenses/gpl-3.0.txt)
33

4+
from __future__ import annotations
5+
6+
47
def dictfilter(item, keys):
58
return dict((k, item[k]) for k in item if k in keys)
69

710

8-
class FilterModule(object):
11+
class FilterModule:
912
def filters(self):
1013
return dict(
1114
dictfilter=dictfilter,

plugins/filter/ec2_az_vpc_route_tables_subnets.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright (C) 2016 Matt Clay <[email protected]>
22
# GNU General Public License v3.0+ (see LICENSE.md or https://www.gnu.org/licenses/gpl-3.0.txt)
33

4+
from __future__ import annotations
5+
46

57
def ec2_az_vpc_route_tables_subnets(zones, subnet):
68
return [map_zone_to_subnet(z, subnet) for z in zones]
@@ -11,7 +13,7 @@ def map_zone_to_subnet(zone, subnet):
1113
return subnet % position
1214

1315

14-
class FilterModule(object):
16+
class FilterModule:
1517
def filters(self):
1618
return dict(
1719
ec2_az_vpc_route_tables_subnets=ec2_az_vpc_route_tables_subnets,

plugins/filter/ec2_az_vpc_subnets.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Copyright (C) 2016 Matt Clay <[email protected]>
22
# GNU General Public License v3.0+ (see LICENSE.md or https://www.gnu.org/licenses/gpl-3.0.txt)
33

4+
from __future__ import annotations
5+
6+
47
def ec2_az_vpc_subnets(zones, subnet, name):
58
return [dict(
69
cidr=map_zone_to_subnet(z, subnet),
@@ -16,7 +19,7 @@ def map_zone_to_subnet(zone, subnet):
1619
return subnet % position
1720

1821

19-
class FilterModule(object):
22+
class FilterModule:
2023
def filters(self):
2124
return dict(
2225
ec2_az_vpc_subnets=ec2_az_vpc_subnets,

plugins/filter/ec2_az_vpc_subnets.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ DOCUMENTATION:
22
name: ec2_az_vpc_subnets
33
short_description: generate a list of availability zones and subnets
44
description:
5-
- Use the input zones dictionary, provided subnet format string and tag name to build a list of availiability zones with subnets.
5+
- Use the input zones dictionary, provided subnet format string and tag name to build a list of availability zones with subnets.
66
positional: _input, subnet, name
77
options:
88
_input:

plugins/filter/map_format.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# Copyright (C) 2017 Matt Clay <[email protected]>
22
# GNU General Public License v3.0+ (see LICENSE.md or https://www.gnu.org/licenses/gpl-3.0.txt)
33

4+
from __future__ import annotations
5+
6+
47
def map_format(item, fmt, *args, **kwargs):
58
d = {}
69
d.update(item)
710
d.update(kwargs)
811
return fmt.format(*args, **d)
912

1013

11-
class FilterModule(object):
14+
class FilterModule:
1215
def filters(self):
1316
return dict(
1417
map_format=map_format,

plugins/module_utils/__init__.py

Whitespace-only changes.

plugins/module_utils/aws.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from __future__ import annotations
2+
3+
import functools
4+
import typing as t
5+
6+
if t.TYPE_CHECKING:
7+
import boto3 as t_boto3
8+
9+
from types_boto3_apigateway import APIGatewayClient
10+
from types_boto3_ec2 import EC2Client
11+
from types_boto3_events import EventBridgeClient
12+
from types_boto3_lambda import LambdaClient
13+
from types_boto3_sqs.service_resource import SQSServiceResource
14+
from types_boto3_sts import STSClient
15+
16+
17+
from ansible.module_utils.basic import AnsibleModule
18+
19+
20+
class AwsModule(AnsibleModule):
21+
@functools.cached_property
22+
def client(self) -> AwsClient:
23+
return AwsClient(self)
24+
25+
@functools.cached_property
26+
def resource(self) -> AwsResource:
27+
return AwsResource(self)
28+
29+
@functools.cached_property
30+
def account_id(self) -> str:
31+
return self.client.sts.get_caller_identity()["Account"]
32+
33+
@functools.cached_property
34+
def region(self) -> str:
35+
return self.session.region_name
36+
37+
@functools.cached_property
38+
def session(self) -> t_boto3.Session:
39+
import boto3
40+
41+
return boto3.Session()
42+
43+
44+
class AwsClient:
45+
def __init__(self, module: AwsModule) -> None:
46+
self._module = module
47+
48+
def _client(self, service_name: str) -> t.Any:
49+
return self._module.session.client(service_name)
50+
51+
@functools.cached_property
52+
def apigateway(self) -> APIGatewayClient:
53+
return self._client('apigateway')
54+
55+
@functools.cached_property
56+
def awslambda(self) -> LambdaClient:
57+
return self._client('lambda')
58+
59+
@functools.cached_property
60+
def ec2(self) -> EC2Client:
61+
return self._client('ec2')
62+
63+
@functools.cached_property
64+
def events(self) -> EventBridgeClient:
65+
return self._client('events')
66+
67+
@functools.cached_property
68+
def sts(self) -> STSClient:
69+
return self._client('sts')
70+
71+
72+
class AwsResource:
73+
def __init__(self, module: AwsModule) -> None:
74+
self._module = module
75+
76+
def _resource(self, service_name: str) -> t.Any:
77+
return self._module.session.resource(service_name)
78+
79+
@functools.cached_property
80+
def sqs(self) -> SQSServiceResource:
81+
return self._resource('sqs')

plugins/modules/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)