class Terraforming::Resource::SQS

Public Class Methods

new(client) click to toggle source
# File lib/terraforming/resource/sqs.rb, line 14
def initialize(client)
  @client = client
end
tf(client: Aws::SQS::Client.new) click to toggle source
# File lib/terraforming/resource/sqs.rb, line 6
def self.tf(client: Aws::SQS::Client.new)
  self.new(client).tf
end
tfstate(client: Aws::SQS::Client.new) click to toggle source
# File lib/terraforming/resource/sqs.rb, line 10
def self.tfstate(client: Aws::SQS::Client.new)
  self.new(client).tfstate
end

Public Instance Methods

tf() click to toggle source
# File lib/terraforming/resource/sqs.rb, line 18
def tf
  apply_template(@client, "tf/sqs")
end
tfstate() click to toggle source
# File lib/terraforming/resource/sqs.rb, line 22
def tfstate
  queues.inject({}) do |resources, queue|
    attributes = {
      "name"                       => module_name_of(queue),
      "id"                         => queue["QueueUrl"],
      "arn"                        => queue["QueueArn"],
      "visibility_timeout_seconds" => queue["VisibilityTimeout"],
      "message_retention_seconds"  => queue["MessageRetentionPeriod"],
      "max_message_size"           => queue["MaximumMessageSize"],
      "delay_seconds"              => queue["DelaySeconds"],
      "receive_wait_time_seconds"  => queue["ReceiveMessageWaitTimeSeconds"],
      "policy"                     => queue.key?("Policy") ? queue["Policy"] : "",
      "redrive_policy"             => queue.key?("RedrivePolicy") ? queue["RedrivePolicy"] : "",
    }
    resources["aws_sqs_queue.#{module_name_of(queue)}"] = {
      "type" => "aws_sqs_queue",
      "primary" => {
        "id"         => queue["QueueUrl"],
        "attributes" => attributes,
      }
    }

    resources
  end
end

Private Instance Methods

module_name_of(queue) click to toggle source
# File lib/terraforming/resource/sqs.rb, line 65
def module_name_of(queue)
  normalize_module_name(queue["QueueArn"].split(":").last)
end
queue_urls() click to toggle source
# File lib/terraforming/resource/sqs.rb, line 61
def queue_urls
  @client.list_queues.map(&:queue_urls).flatten
end
queues() click to toggle source
# File lib/terraforming/resource/sqs.rb, line 50
def queues
  queue_urls.map do |queue_url|
    attributes = @client.get_queue_attributes({
      queue_url: queue_url,
      attribute_names: ["All"],
    }).attributes
    attributes["QueueUrl"] = queue_url
    attributes
  end
end