Sha256: 2f41596bbe63a83deb8a0c26283d7a6a57a931be463a84166aac15578ffa1ae7

Contents?: true

Size: 1.66 KB

Versions: 3

Compression:

Stored size: 1.66 KB

Contents

require 'thor'
require 'awspec/setup'

module Awspec
  class Generate < Thor
    class_option :profile

    types = %w(
      vpc ec2 rds security_group elb network_acl route_table subnet nat_gateway
    )

    types.each do |type|
      desc type + ' [vpc_id]', "Generate #{type} spec from VPC ID (or VPC \"Name\" tag)"
      define_method type do |*args|
        Awsecrets.load(profile: options[:profile])
        vpc_id = args.first
        eval "puts Awspec::Generator::Spec::#{type.camelize}.new.generate_by_vpc_id(vpc_id)"
      end
    end

    desc 'route53_hosted_zone [example.com.]', 'Generate route53_hosted_zone spec from Domain name'
    def route53_hosted_zone(hosted_zone)
      Awsecrets.load(profile: options[:profile])
      puts Awspec::Generator::Spec::Route53HostedZone.new.generate_by_domain_name(hosted_zone)
    end

    desc 's3_bucket [backet_name]', 'Generate s3_bucket spec from S3 bucket name. if NO args, Generate all.'
    def s3_bucket(bucket_name = nil)
      Awsecrets.load(profile: options[:profile])
      if bucket_name
        puts Awspec::Generator::Spec::S3Bucket.new.generate(bucket_name)
      else
        puts Awspec::Generator::Spec::S3Bucket.new.generate_all
      end
    end

    types_for_generate_all = %w(
      iam_policy cloudwatch_alarm directconnect ebs
    )

    types_for_generate_all.each do |type|
      if %w(iam_policy ebs).include?(type)
        desc type, "Generate attached #{type} spec"
      else
        desc type, "Generate #{type} spec"
      end
      define_method type do
        Awsecrets.load(profile: options[:profile])
        eval "puts Awspec::Generator::Spec::#{type.camelize}.new.generate_all"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
awspec-0.33.0 lib/awspec/command/generate.rb
awspec-0.32.0 lib/awspec/command/generate.rb
awspec-0.31.0 lib/awspec/command/generate.rb