Skip to content

Commit

Permalink
Merge pull request #75 from k1LoW/add-type-directconnect_virtual_inte…
Browse files Browse the repository at this point in the history
…rface

Add directconnect_virtual_interface type
  • Loading branch information
k1LoW committed Nov 18, 2015
2 parents af7416b + d888966 commit fb754c7
Show file tree
Hide file tree
Showing 13 changed files with 178 additions and 31 deletions.
30 changes: 1 addition & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,35 +86,7 @@ $ export AWS_PROFILE=mycreds; bundle exec rake spec

## Support AWS Resources

- [x] EC2 (`ec2`)
- [x] RDS (`rds`)
- [x] RDS DB Parameter Group (`rds_db_parameter_group`)
- [x] Security Group (`security_group`)
- [x] VPC (`vpc`)
- [x] S3 (`s3`)
- Route53
- [x] Route53 Hosted Zone (`route53_hosted_zone`)
- AutoScaling
- [x] AutoScaling Group (`autoscaling_group`)
- [x] Subnet (`subnet`)
- [x] RouteTable (`route_table`)
- [x] EBS Volume (`ebs`)
- [x] ELB (`elb`)
- [x] Lambda (`lambda`)
- IAM
- [x] IAM User (`iam_user`)
- [x] IAM Group (`iam_group`)
- [x] IAM Role (`iam_role`)
- [x] IAM Policy (`iam_policy`)
- [x] ElastiCache (`elasticache`)
- [x] ElastiCache Cache Parameter Group (`elasticache_cache_parameter_group`)
- CloudWatch
- [x] CloudWatch Alarm (`cloudwatch_alarm`)
- SES
- [x] SES Identity (`ses_identity`)
- [x] NetworkAcl (`network_acl`)

[Resource Types more infomation here](doc/resource_types.md)
[Resource Types infomation here](doc/resource_types.md)

## References

Expand Down
22 changes: 22 additions & 0 deletions doc/resource_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
| [cloudwatch_alarm](#cloudwatch_alarm)
| [ses_identity](#ses_identity)
| [network_acl](#network_acl)
| [directconnect_virtual_interface](#directconnect_virtual_interface)

## <a name="ec2">ec2</a>

Expand Down Expand Up @@ -461,3 +462,24 @@ end
```

#### its(:inbound_entries_count), its(:outbound_entries_count), its(:network_acl_id), its(:vpc_id), its(:is_default)
## <a name="directconnect_virtual_interface">directconnect_virtual_interface</a>

DirectconnectVirtualInterface resource type.

### exist

### be_available

### be_confirming

### be_deleted

### be_deleting

### be_pending

### be_rejected

### be_verifying

#### its(:owner_account), its(:virtual_interface_id), its(:location), its(:connection_id), its(:virtual_interface_type), its(:virtual_interface_name), its(:vlan), its(:asn), its(:auth_key), its(:amazon_address), its(:customer_address), its(:virtual_interface_state), its(:customer_router_config), its(:virtual_gateway_id)
2 changes: 1 addition & 1 deletion lib/awspec/command/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def route53_hosted_zone(hosted_zone)
end

types_for_generate_all = %w(
iam_policy cloudwatch_alarm
iam_policy cloudwatch_alarm directconnect
)

types_for_generate_all.each do |type|
Expand Down
1 change: 1 addition & 0 deletions lib/awspec/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require 'awspec/generator/spec/network_acl'
require 'awspec/generator/spec/route_table'
require 'awspec/generator/spec/subnet'
require 'awspec/generator/spec/directconnect'

# Doc
require 'awspec/generator/doc/type'
Expand Down
17 changes: 17 additions & 0 deletions lib/awspec/generator/doc/type/directconnect_virtual_interface.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Awspec::Generator
module Doc
module Type
class DirectconnectVirtualInterface < Base
def initialize
super
@type_name = 'DirectconnectVirtualInterface'
@type = Awspec::Type::DirectconnectVirtualInterface.new('my-directconnect-virtual-interface')
@ret = @type.resource
@matchers = []
@ignore_matchers = []
@describes = []
end
end
end
end
end
33 changes: 33 additions & 0 deletions lib/awspec/generator/spec/directconnect.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Awspec::Generator
module Spec
class Directconnect
include Awspec::Helper::Finder
def generate_all
generate_virtual_interface_all
end

def generate_virtual_interface_all
virtual_interfaces = select_virtual_interfaces
virtual_interfaces.empty? && fail('Not Found virtual_interfaces')
ERB.new(virtual_interface_spec_template, nil, '-').result(binding).chomp
end

def virtual_interface_spec_template
template = <<-'EOF'
<% virtual_interfaces.each do |interface| %>
describe directconnect_virtual_interface('<%= interface.virtual_interface_name %>') do
it { should exist }
it { should be_<%= interface.virtual_interface_state %> }
its(:connection_id) { should eq '<%= interface.connection_id %>' }
its(:virtual_interface_id) { should eq '<%= interface.virtual_interface_id %>' }
its(:amazon_address) { should eq '<%= interface.amazon_address %>' }
its(:customer_address) { should eq '<%= interface.customer_address %>' }
its(:virtual_gateway_id) { should eq '<%= interface.virtual_gateway_id %>' }
end
<% end %>
EOF
template
end
end
end
end
3 changes: 3 additions & 0 deletions lib/awspec/helper/finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require 'awspec/helper/finder/elasticache'
require 'awspec/helper/finder/cloudwatch'
require 'awspec/helper/finder/ses'
require 'awspec/helper/finder/directconnect'

module Awspec::Helper
module Finder
Expand All @@ -31,6 +32,7 @@ module Finder
include Awspec::Helper::Finder::Elasticache
include Awspec::Helper::Finder::Cloudwatch
include Awspec::Helper::Finder::Ses
include Awspec::Helper::Finder::Directconnect

# rubocop:disable all
def initialize(id = nil)
Expand All @@ -45,6 +47,7 @@ def initialize(id = nil)
@elasticache_client = Aws::ElastiCache::Client.new
@cloudwatch_client = Aws::CloudWatch::Client.new
@ses_client = Aws::SES::Client.new
@directconnect_client = Aws::DirectConnect::Client.new
end
end
end
19 changes: 19 additions & 0 deletions lib/awspec/helper/finder/directconnect.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Awspec::Helper
module Finder
module Directconnect
def find_virtual_interface(virtual_interface_id)
res = @directconnect_client.describe_virtual_interfaces
ret = res.virtual_interfaces.select do |virtual_interface|
next true if virtual_interface.virtual_interface_id == virtual_interface_id
next true if virtual_interface.virtual_interface_name == virtual_interface_id
end
return ret.first if ret.count == 1
end

def select_virtual_interfaces
res = @directconnect_client.describe_virtual_interfaces
res.virtual_interfaces
end
end
end
end
2 changes: 1 addition & 1 deletion lib/awspec/helper/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Type
vpc s3 route53_hosted_zone autoscaling_group subnet
route_table ebs elb lambda iam_user iam_group iam_role
iam_policy elasticache elasticache_cache_parameter_group
cloudwatch_alarm ses_identity network_acl
cloudwatch_alarm ses_identity network_acl directconnect_virtual_interface
)

TYPES.each do |type|
Expand Down
25 changes: 25 additions & 0 deletions lib/awspec/stub/directconnect_virtual_interface.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Aws.config[:directconnect] = {
stub_responses: {
describe_virtual_interfaces: {
virtual_interfaces: [
{
owner_account: '123456789012',
virtual_interface_id: 'dxvif-aabbccdd',
location: 'AbCD5',
connection_id: 'dxcon-abcd5fgh',
virtual_interface_type: 'private',
virtual_interface_name: 'my-directconnect-virtual-interface',
vlan: 400,
asn: 65_007,
auth_key: nil,
amazon_address: '170.252.252.1/30',
customer_address: '123.456.789.2/30',
virtual_interface_state: 'available',
customer_router_config: nil,
virtual_gateway_id: 'vgw-d234e5f6',
route_filter_prefixes: []
}
]
}
}
}
20 changes: 20 additions & 0 deletions lib/awspec/type/directconnect_virtual_interface.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Awspec::Type
class DirectconnectVirtualInterface < Base
def initialize(id)
super
@resource = find_virtual_interface(id)
@id = @resource[:virtual_interface_id] if @resource
end

states = %w(
confirming verifying pending available
deleting deleted rejected
)

states.each do |state|
define_method state + '?' do
@resource[:virtual_interface_state] == state
end
end
end
end
23 changes: 23 additions & 0 deletions spec/generator/spec/directconnect_virtual_interface_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper'

describe 'Awspec::Generator::Spec::Directconnect' do
before do
Awspec::Stub.load 'directconnect_virtual_interface'
end
let(:directconnect) { Awspec::Generator::Spec::Directconnect.new }
it 'generate_by_vpc_id generate spec' do
spec = <<-'EOF'
describe directconnect_virtual_interface('my-directconnect-virtual-interface') do
it { should exist }
it { should be_available }
its(:connection_id) { should eq 'dxcon-abcd5fgh' }
its(:virtual_interface_id) { should eq 'dxvif-aabbccdd' }
its(:amazon_address) { should eq '170.252.252.1/30' }
its(:customer_address) { should eq '123.456.789.2/30' }
its(:virtual_gateway_id) { should eq 'vgw-d234e5f6' }
end
EOF
expect(directconnect.generate_all.to_s.gsub(/\n/, "\n")).to eq spec
end
end
12 changes: 12 additions & 0 deletions spec/type/directconnect_virtual_interface_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'spec_helper'
Awspec::Stub.load 'directconnect_virtual_interface'

describe directconnect_virtual_interface('my-directconnect-virtual-interface') do
it { should exist }
it { should be_available }
its(:connection_id) { should eq 'dxcon-abcd5fgh' }
its(:virtual_interface_id) { should eq 'dxvif-aabbccdd' }
its(:amazon_address) { should eq '170.252.252.1/30' }
its(:customer_address) { should eq '123.456.789.2/30' }
its(:virtual_gateway_id) { should eq 'vgw-d234e5f6' }
end

0 comments on commit fb754c7

Please sign in to comment.