class Terraforming::Resource::SNSTopic
Public Class Methods
new(client)
click to toggle source
# File lib/terraforming/resource/sns_topic.rb, line 14 def initialize(client) @client = client end
tf(client: Aws::SNS::Client.new)
click to toggle source
# File lib/terraforming/resource/sns_topic.rb, line 6 def self.tf(client: Aws::SNS::Client.new) self.new(client).tf end
tfstate(client: Aws::SNS::Client.new)
click to toggle source
# File lib/terraforming/resource/sns_topic.rb, line 10 def self.tfstate(client: Aws::SNS::Client.new) self.new(client).tfstate end
Public Instance Methods
tf()
click to toggle source
# File lib/terraforming/resource/sns_topic.rb, line 18 def tf apply_template(@client, "tf/sns_topic") end
tfstate()
click to toggle source
# File lib/terraforming/resource/sns_topic.rb, line 22 def tfstate topics.inject({}) do |resources, topic| attributes = { "name" => module_name_of(topic), "id" => topic["TopicArn"], "arn" => topic["TopicArn"], "display_name" => topic["DisplayName"], "policy" => topic.key?("Policy") ? topic["Policy"] : "", "delivery_policy" => topic.key?("DeliveryPolicy") ? topic["DeliveryPolicy"] : "" } resources["aws_sns_topic.#{module_name_of(topic)}"] = { "type" => "aws_sns_topic", "primary" => { "id" => topic["TopicArn"], "attributes" => attributes } } resources end end
Private Instance Methods
module_name_of(topic)
click to toggle source
# File lib/terraforming/resource/sns_topic.rb, line 70 def module_name_of(topic) normalize_module_name(topic["TopicArn"].split(":").last) end
topic_arns()
click to toggle source
# File lib/terraforming/resource/sns_topic.rb, line 56 def topic_arns token = "" arns = [] loop do resp = @client.list_topics(next_token: token) arns += resp.topics.map(&:topic_arn).flatten token = resp.next_token break if token.nil? end arns end
topics()
click to toggle source
# File lib/terraforming/resource/sns_topic.rb, line 46 def topics topic_arns.map do |topic_arn| attributes = @client.get_topic_attributes({ topic_arn: topic_arn, }).attributes attributes["TopicArn"] = topic_arn attributes end end