Skip to content

Commit

Permalink
sns_topic - Fix bug when used in GovCloud - issue 836 (ansible-collec…
Browse files Browse the repository at this point in the history
…tions#1195)

SUMMARY

Add region detection to skip usage of FIFO topics when using GovCloud regions
Fixes ansible-collections#836
ISSUE TYPE

    Bugfix Pull Request

COMPONENT NAME

community.aws.sns_topic


* * Add endpoint detection to skip usage of FIFO topics for GovCloud regions
* * Remove GovCloud hack for FIFO topics
* Update plugins/modules/sns_topic.py
* Update plugins/modules/sns_topic.py
* minor docs tweak
  • Loading branch information
Razique authored Jun 29, 2022
1 parent b113be5 commit 2d74eda
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions plugins/modules/sns_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
type: str
topic_type:
description:
- The type of topic that should be created. Either Standard for FIFO (first-in, first-out)
choices: ['standard', 'fifo']
- The type of topic that should be created. Either Standard for FIFO (first-in, first-out).
- Some regions, including GovCloud regions do not support FIFO topics.
Use a default value of 'standard' or omit the option if the region
does not support FIFO topics.
choices: ["standard", "fifo"]
default: 'standard'
type: str
version_added: 2.0.0
Expand Down Expand Up @@ -363,17 +366,21 @@ def __init__(self,
self.attributes_set = []

def _create_topic(self):
attributes = {'FifoTopic': 'false'}
attributes = {}
tags = []

# NOTE: Never set FifoTopic = False. Some regions (including GovCloud)
# don't support the attribute being set, even to False.
if self.topic_type == 'fifo':
attributes['FifoTopic'] = 'true'
if not self.name.endswith('.fifo'):
self.name = self.name + '.fifo'

if not self.check_mode:
try:
response = self.connection.create_topic(Name=self.name, Attributes=attributes, Tags=tags)
response = self.connection.create_topic(Name=self.name,
Attributes=attributes,
Tags=tags)
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
self.module.fail_json_aws(e, msg="Couldn't create topic %s" % self.name)
self.topic_arn = response['TopicArn']
Expand Down Expand Up @@ -506,7 +513,6 @@ def ensure_gone(self):


def main():

# We're kinda stuck with CamelCase here, it would be nice to switch to
# snake_case, but we'd need to purge out the alias entries
http_retry_args = dict(
Expand Down

0 comments on commit 2d74eda

Please sign in to comment.