class Terraforming::Resource::VPC

Public Class Methods

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

Public Instance Methods

tf() click to toggle source
# File lib/terraforming/resource/vpc.rb, line 18
def tf
  apply_template(@client, "tf/vpc")
end
tfstate() click to toggle source
# File lib/terraforming/resource/vpc.rb, line 22
def tfstate
  vpcs.inject({}) do |resources, vpc|
    attributes = {
      "cidr_block" => vpc.cidr_block,
      "enable_dns_hostnames" => enable_dns_hostnames?(vpc).to_s,
      "enable_dns_support" => enable_dns_support?(vpc).to_s,
      "id" => vpc.vpc_id,
      "instance_tenancy" => vpc.instance_tenancy,
      "tags.#" => vpc.tags.length.to_s,
    }
    resources["aws_vpc.#{module_name_of(vpc)}"] = {
      "type" => "aws_vpc",
      "primary" => {
        "id" => vpc.vpc_id,
        "attributes" => attributes
      }
    }

    resources
  end
end

Private Instance Methods

enable_dns_hostnames?(vpc) click to toggle source
# File lib/terraforming/resource/vpc.rb, line 46
def enable_dns_hostnames?(vpc)
  vpc_attribute(vpc, :enableDnsHostnames).enable_dns_hostnames.value
end
enable_dns_support?(vpc) click to toggle source
# File lib/terraforming/resource/vpc.rb, line 50
def enable_dns_support?(vpc)
  vpc_attribute(vpc, :enableDnsSupport).enable_dns_support.value
end
module_name_of(vpc) click to toggle source
# File lib/terraforming/resource/vpc.rb, line 54
def module_name_of(vpc)
  normalize_module_name(name_from_tag(vpc, vpc.vpc_id))
end
vpc_attribute(vpc, attribute) click to toggle source
# File lib/terraforming/resource/vpc.rb, line 62
def vpc_attribute(vpc, attribute)
  @client.describe_vpc_attribute(vpc_id: vpc.vpc_id, attribute: attribute)
end
vpcs() click to toggle source
# File lib/terraforming/resource/vpc.rb, line 58
def vpcs
  @client.describe_vpcs.map(&:vpcs).flatten
end