Sha256: 5b0eed21ccd841750865f2697fbf9d57e464eb9468e7e99a0f0bae87055a279d

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

module Terraforming
  module Resource
    class VPNGateway
      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/vpn_gateway")
      end

      def tfstate
        vpn_gateways.inject({}) do |resources, vpn_gateway|
          next resources if vpn_gateway.vpc_attachments.empty?

          attributes = {
            "id"     => vpn_gateway.vpn_gateway_id,
            "vpc_id" => vpn_gateway.vpc_attachments[0].vpc_id,
            "availability_zone" => vpn_gateway.availability_zone,
            "tags.#" => vpn_gateway.tags.length.to_s,
          }
          resources["aws_vpn_gateway.#{module_name_of(vpn_gateway)}"] = {
            "type" => "aws_vpn_gateway",
            "primary" => {
              "id"         => vpn_gateway.vpn_gateway_id,
              "attributes" => attributes
            }
          }

          resources
        end
      end

      private

      def vpn_gateways
        @client.describe_vpn_gateways.vpn_gateways
      end

      def module_name_of(vpn_gateway)
        normalize_module_name(name_from_tag(vpn_gateway, vpn_gateway.vpn_gateway_id))
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
terraforming-0.9.1 lib/terraforming/resource/vpn_gateway.rb
terraforming-0.9.0 lib/terraforming/resource/vpn_gateway.rb
terraforming-0.8.0 lib/terraforming/resource/vpn_gateway.rb