Sha256: 00370740b0ceee81064ade1787209996d39ac511a24068c6518105d4a448fa5e

Contents?: true

Size: 1.56 KB

Versions: 13

Compression:

Stored size: 1.56 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.reject { |association| association.subnet_id.nil? }
      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.map(&:route_tables).flatten
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
terraforming-0.18.0 lib/terraforming/resource/route_table_association.rb
terraforming-0.17.0 lib/terraforming/resource/route_table_association.rb
terraforming-0.16.0 lib/terraforming/resource/route_table_association.rb
terraforming-0.15.0 lib/terraforming/resource/route_table_association.rb
aws-insight-0.14.1 lib/terraforming/resource/route_table_association.rb
aws-insight-0.14.0 lib/terraforming/resource/route_table_association.rb
terraforming-0.14.0 lib/terraforming/resource/route_table_association.rb
terraforming-0.13.2 lib/terraforming/resource/route_table_association.rb
terraforming-0.13.1 lib/terraforming/resource/route_table_association.rb
terraforming-0.13.0 lib/terraforming/resource/route_table_association.rb
terraforming-0.12.0 lib/terraforming/resource/route_table_association.rb
terraforming-0.11.0 lib/terraforming/resource/route_table_association.rb
terraforming-0.10.0 lib/terraforming/resource/route_table_association.rb