Skip to content

Commit

Permalink
[PR #1195/2d74eda7 backport][stable-4] sns_topic - Fix bug when used …
Browse files Browse the repository at this point in the history
…in GovCloud - issue 836 (#1275)

[PR #1195/2d74eda7 backport][stable-4] sns_topic - Fix bug when used in GovCloud - issue 836

This is a backport of PR #1195 as merged into main (2d74eda).
SUMMARY
Add region detection to skip usage of FIFO topics when using GovCloud regions
Fixes #836
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
community.aws.sns_topic

Reviewed-by: Mark Chappell <None>
  • Loading branch information
patchback[bot] authored Jun 29, 2022
1 parent 974c3f0 commit 2e9f9e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1195-sns_topic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- sns_topic - fix bug which prevented the module being used in GovCloud (https://github.com/ansible-collections/community.aws/issues/836).
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 2e9f9e0

Please sign in to comment.