lib/terraforming/cli.rb in terraforming-0.0.5 vs lib/terraforming/cli.rb in terraforming-0.1.0
- old
+ new
@@ -1,117 +1,130 @@
module Terraforming
class CLI < Thor
+ class_option :merge, type: :string, desc: "tfstate file to merge"
+ class_option :tfstate, type: :boolean, desc: "Generate tfstate"
+
desc "dbpg", "Database Parameter Group"
- option :tfstate, type: :boolean
def dbpg
execute(Terraforming::Resource::DBParameterGroup, options)
end
desc "dbsg", "Database Security Group"
- option :tfstate, type: :boolean
def dbsg
execute(Terraforming::Resource::DBSecurityGroup, options)
end
desc "dbsn", "Database Subnet Group"
- option :tfstate, type: :boolean
def dbsn
execute(Terraforming::Resource::DBSubnetGroup, options)
end
desc "ec2", "EC2"
- option :tfstate, type: :boolean
def ec2
execute(Terraforming::Resource::EC2, options)
end
desc "elb", "ELB"
- option :tfstate, type: :boolean
def elb
execute(Terraforming::Resource::ELB, options)
end
desc "iamg", "IAM Group"
- option :tfstate, type: :boolean
def iamg
execute(Terraforming::Resource::IAMGroup, options)
end
desc "iamgp", "IAM Group Policy"
- option :tfstate, type: :boolean
def iamgp
execute(Terraforming::Resource::IAMGroupPolicy, options)
end
+ desc "iamip", "IAM Instance Profile"
+ def iamip
+ execute(Terraforming::Resource::IAMInstanceProfile, options)
+ end
+
desc "iamp", "IAM Policy"
- option :tfstate, type: :boolean
def iamp
execute(Terraforming::Resource::IAMPolicy, options)
end
+ desc "iamr", "IAM Role"
+ def iamr
+ execute(Terraforming::Resource::IAMRole, options)
+ end
+
+ desc "iamrp", "IAM Role Policy"
+ def iamrp
+ execute(Terraforming::Resource::IAMRolePolicy, options)
+ end
+
desc "iamu", "IAM User"
- option :tfstate, type: :boolean
def iamu
execute(Terraforming::Resource::IAMUser, options)
end
desc "iamup", "IAM User Policy"
- option :tfstate, type: :boolean
def iamup
execute(Terraforming::Resource::IAMUserPolicy, options)
end
desc "nacl", "Network ACL"
- option :tfstate, type: :boolean
def nacl
execute(Terraforming::Resource::NetworkACL, options)
end
desc "r53r", "Route53 Record"
- option :tfstate, type: :boolean
def r53r
execute(Terraforming::Resource::Route53Record, options)
end
desc "r53z", "Route53 Hosted Zone"
- option :tfstate, type: :boolean
def r53z
execute(Terraforming::Resource::Route53Zone, options)
end
desc "rds", "RDS"
- option :tfstate, type: :boolean
def rds
execute(Terraforming::Resource::RDS, options)
end
desc "s3", "S3"
- option :tfstate, type: :boolean
def s3
execute(Terraforming::Resource::S3, options)
end
- desc "sg", "SecurityGroup"
- option :tfstate, type: :boolean
+ desc "sg", "Security Group"
def sg
execute(Terraforming::Resource::SecurityGroup, options)
end
desc "sn", "Subnet"
- option :tfstate, type: :boolean
def sn
execute(Terraforming::Resource::Subnet, options)
end
desc "vpc", "VPC"
- option :tfstate, type: :boolean
def vpc
execute(Terraforming::Resource::VPC, options)
end
private
def execute(klass, options)
- puts options[:tfstate] ? klass.tfstate : klass.tf
+ result = if options[:tfstate]
+ tfstate(klass, options[:merge])
+ else
+ klass.tf
+ end
+
+ puts result
+ end
+
+ def tfstate(klass, tfstate_path)
+ return klass.tfstate unless tfstate_path
+
+ base_tfstate = JSON.parse(open(tfstate_path).read)
+ klass.tfstate(tfstate_base: base_tfstate)
end
end
end