| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: Ansible Project |
| 5 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
DOCUMENTATION = r""" |
| 8 |
module: sns_topic_info |
| 9 |
short_description: sns_topic_info module |
| 10 |
version_added: 3.2.0 |
| 11 |
description: |
| 12 |
- The M(community.aws.sns_topic_info) module allows to get all AWS SNS topics or properties of a specific AWS SNS topic. |
| 13 |
author: |
| 14 |
- "Alina Buzachis (@alinabuzachis)" |
| 15 |
options: |
| 16 |
topic_arn: |
| 17 |
description: The ARN of the AWS SNS topic for which you wish to find subscriptions or list attributes. |
| 18 |
required: false |
| 19 |
type: str |
| 20 |
extends_documentation_fragment: |
| 21 |
- amazon.aws.common.modules |
| 22 |
- amazon.aws.region.modules |
| 23 |
- amazon.aws.boto3 |
| 24 |
""" |
| 25 |
|
| 26 |
EXAMPLES = r""" |
| 27 |
- name: list all the topics |
| 28 |
community.aws.sns_topic_info: |
| 29 |
register: sns_topic_list |
| 30 |
|
| 31 |
- name: get info on specific topic |
| 32 |
community.aws.sns_topic_info: |
| 33 |
topic_arn: "{{ sns_arn }}" |
| 34 |
register: sns_topic_info |
| 35 |
""" |
| 36 |
|
| 37 |
RETURN = r""" |
| 38 |
result: |
| 39 |
description: |
| 40 |
- The result contaning the details of one or all AWS SNS topics. |
| 41 |
returned: success |
| 42 |
type: list |
| 43 |
contains: |
| 44 |
sns_arn: |
| 45 |
description: The ARN of the topic. |
| 46 |
type: str |
| 47 |
returned: always |
| 48 |
sample: "arn:aws:sns:us-east-2:123456789012:my_topic_name" |
| 49 |
sns_topic: |
| 50 |
description: Dict of sns topic details. |
| 51 |
type: complex |
| 52 |
returned: always |
| 53 |
contains: |
| 54 |
content_based_deduplication: |
| 55 |
description: Whether or not content_based_deduplication was set |
| 56 |
returned: always |
| 57 |
type: str |
| 58 |
sample: "true" |
| 59 |
delivery_policy: |
| 60 |
description: Delivery policy for the SNS topic. |
| 61 |
returned: when topic is owned by this AWS account |
| 62 |
type: str |
| 63 |
sample: > |
| 64 |
{"http":{"defaultHealthyRetryPolicy":{"minDelayTarget":20,"maxDelayTarget":20,"numRetries":3,"numMaxDelayRetries":0, |
| 65 |
"numNoDelayRetries":0,"numMinDelayRetries":0,"backoffFunction":"linear"},"disableSubscriptionOverrides":false}} |
| 66 |
display_name: |
| 67 |
description: Display name for SNS topic. |
| 68 |
returned: when topic is owned by this AWS account |
| 69 |
type: str |
| 70 |
sample: My topic name |
| 71 |
owner: |
| 72 |
description: AWS account that owns the topic. |
| 73 |
returned: when topic is owned by this AWS account |
| 74 |
type: str |
| 75 |
sample: '123456789012' |
| 76 |
policy: |
| 77 |
description: Policy for the SNS topic. |
| 78 |
returned: when topic is owned by this AWS account |
| 79 |
type: str |
| 80 |
sample: > |
| 81 |
{"Version":"2012-10-17","Id":"SomePolicyId","Statement":[{"Sid":"ANewSid","Effect":"Allow","Principal":{"AWS":"arn:aws:iam::123456789012:root"}, |
| 82 |
"Action":"sns:Subscribe","Resource":"arn:aws:sns:us-east-2:123456789012:ansible-test-dummy-topic","Condition":{"StringEquals":{"sns:Protocol":"email"}}}]} |
| 83 |
subscriptions: |
| 84 |
description: List of subscribers to the topic in this AWS account. |
| 85 |
returned: always |
| 86 |
type: list |
| 87 |
sample: [] |
| 88 |
subscriptions_added: |
| 89 |
description: List of subscribers added in this run. |
| 90 |
returned: always |
| 91 |
type: list |
| 92 |
sample: [] |
| 93 |
subscriptions_confirmed: |
| 94 |
description: Count of confirmed subscriptions. |
| 95 |
returned: when topic is owned by this AWS account |
| 96 |
type: str |
| 97 |
sample: '0' |
| 98 |
subscriptions_deleted: |
| 99 |
description: Count of deleted subscriptions. |
| 100 |
returned: when topic is owned by this AWS account |
| 101 |
type: str |
| 102 |
sample: '0' |
| 103 |
subscriptions_existing: |
| 104 |
description: List of existing subscriptions. |
| 105 |
returned: always |
| 106 |
type: list |
| 107 |
sample: [] |
| 108 |
subscriptions_new: |
| 109 |
description: List of new subscriptions. |
| 110 |
returned: always |
| 111 |
type: list |
| 112 |
sample: [] |
| 113 |
subscriptions_pending: |
| 114 |
description: Count of pending subscriptions. |
| 115 |
returned: when topic is owned by this AWS account |
| 116 |
type: str |
| 117 |
sample: '0' |
| 118 |
subscriptions_purge: |
| 119 |
description: Whether or not purge_subscriptions was set. |
| 120 |
returned: always |
| 121 |
type: bool |
| 122 |
sample: true |
| 123 |
topic_arn: |
| 124 |
description: ARN of the SNS topic (equivalent to sns_arn). |
| 125 |
returned: when topic is owned by this AWS account |
| 126 |
type: str |
| 127 |
sample: arn:aws:sns:us-east-2:123456789012:ansible-test-dummy-topic |
| 128 |
topic_type: |
| 129 |
description: The type of topic. |
| 130 |
type: str |
| 131 |
sample: "standard" |
| 132 |
""" |
| 133 |
|
| 134 |
|
| 135 |
try: |
| 136 |
import botocore |
| 137 |
except ImportError: |
| 138 |
pass # handled by AnsibleAWSModule |
| 139 |
|
| 140 |
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry |
| 141 |
|
| 142 |
from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule |
| 143 |
from ansible_collections.community.aws.plugins.module_utils.sns import get_info |
| 144 |
from ansible_collections.community.aws.plugins.module_utils.sns import list_topics |
| 145 |
|
| 146 |
|
| 147 |
def main(): |
| 148 |
argument_spec = dict( |
| 149 |
topic_arn=dict(type="str", required=False), |
| 150 |
) |
| 151 |
|
| 152 |
module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) |
| 153 |
|
| 154 |
topic_arn = module.params.get("topic_arn") |
| 155 |
|
| 156 |
try: |
| 157 |
connection = module.client("sns", retry_decorator=AWSRetry.jittered_backoff()) |
| 158 |
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: |
| 159 |
module.fail_json_aws(e, msg="Failed to connect to AWS.") |
| 160 |
|
| 161 |
if topic_arn: |
| 162 |
results = dict(sns_arn=topic_arn, sns_topic=get_info(connection, module, topic_arn)) |
| 163 |
else: |
| 164 |
results = list_topics(connection, module) |
| 165 |
|
| 166 |
module.exit_json(result=results) |
| 167 |
|
| 168 |
|
| 169 |
if __name__ == "__main__": |
| 170 |
main() |