Sha256: 9baf6ab60c8ce1a6c6da5793300374f4fd2f1002a521bd97cdde309d1c79353a

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

module Terraforming
  module Resource
    class RouteTableAssociation
      include Terraforming::Util

      def self.tf(client: Aws::EC2::Client.new)
        self.new(client).tf
      end

      def self.tfstate(client: Aws::EC2::Client.new)
        self.new(client).tfstate
      end

      def initialize(client)
        @client = client
      end

      def tf
        apply_template(@client, "tf/route_table_association")
      end

      def tfstate
        resources = {}
        route_tables.each do |route_table|
          associations_of(route_table).each do |assoc|
            attributes = {
              "id" => assoc.route_table_association_id,
              "route_table_id" => assoc.route_table_id,
              "subnet_id" => assoc.subnet_id,
            }
            resources["aws_route_table_association.#{module_name_of(route_table, assoc)}"] = {
              "type" => "aws_route_table_association",
              "primary" => {
                "id" => assoc.route_table_association_id,
                "attributes" => attributes
              }
            }
          end
        end
        resources
      end

      private

      def associations_of(route_table)
        route_table.associations
      end

      def module_name_of(route_table, assoc)
        normalize_module_name(name_from_tag(route_table, route_table.route_table_id) + '-' + assoc.route_table_association_id)
      end

      def route_tables
        @client.describe_route_tables.route_tables
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
terraforming-0.6.1 lib/terraforming/resource/route_table_association.rb
terraforming-0.6.0 lib/terraforming/resource/route_table_association.rb