Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

has_tag for ALB #472

Merged
merged 4 commits into from Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 0 additions & 12 deletions .gitignore

This file was deleted.

8 changes: 8 additions & 0 deletions doc/_resource_types/alb.md
Expand Up @@ -37,3 +37,11 @@ describe alb('my-alb') do
it { should belong_to_vpc('my-vpc') }
end
```

### have_tag
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


```ruby
describe alb('my-alb') do
it { should have_tag('environment').value('dev') }
end
```
19 changes: 18 additions & 1 deletion doc/resource_types.md
Expand Up @@ -144,6 +144,22 @@ end
```


### have_tag

```ruby
describe alb('my-alb') do
it { should have_tag('environment').value('dev') }
end
```

### have_tag

```ruby
describe alb('my-alb') do
it { should have_tag('environment').value('dev') }
end
```

### belong_to_vpc

```ruby
Expand All @@ -152,6 +168,7 @@ describe alb('my-alb') do
end
```


### its(:load_balancer_arn), its(:dns_name), its(:canonical_hosted_zone_id), its(:created_time), its(:load_balancer_name), its(:scheme), its(:vpc_id), its(:type), its(:security_groups), its(:ip_address_type)
## <a name="alb_listener">alb_listener</a>

Expand Down Expand Up @@ -274,7 +291,7 @@ describe apigateway('my-apigateway') do
end
```

### its(:id), its(:name), its(:description), its(:created_date), its(:version), its(:warnings), its(:binary_media_types), its(:minimum_compression_size), its(:api_key_source), its(:policy)
### its(:id), its(:name), its(:description), its(:created_date), its(:version), its(:warnings), its(:binary_media_types), its(:minimum_compression_size), its(:api_key_source), its(:policy), its(:tags)
## <a name="autoscaling_group">autoscaling_group</a>

AutoscalingGroup resource type.
Expand Down
3 changes: 2 additions & 1 deletion lib/awspec/generator/doc/type/alb.rb
Expand Up @@ -9,7 +9,8 @@ def initialize
@ret = @type.resource_via_client
@matchers = [
Awspec::Type::Alb::STATES.map { |state| 'be_' + state }.join(', '),
'belong_to_vpc'
'belong_to_vpc',
'have_tag'
]
@ignore_matchers = Awspec::Type::Alb::STATES.map { |state| 'be_' + state }
@describes = []
Expand Down
9 changes: 9 additions & 0 deletions lib/awspec/helper/finder/alb.rb
Expand Up @@ -54,6 +54,15 @@ def select_rule_by_alb_listener_id(id)
end
selected
end

def select_all_alb_tags(id)
res = elbv2_client.describe_tags({ resource_arns: [id] })
res.tag_descriptions.select do |resource|
resource.resource_arn == id
end.first.tags
rescue
return nil
end
end
end
end
9 changes: 9 additions & 0 deletions lib/awspec/stub/alb.rb
Expand Up @@ -81,6 +81,15 @@
protocol: 'HTTP'
}
]
},
describe_tags: {
tag_descriptions: [
resource_arn: 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:loadbalancer/app/my-alb/1aa1bb1cc1ddee11',
tags: [
key: 'environment',
value: 'dev'
]
]
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions lib/awspec/type/alb.rb
@@ -1,5 +1,6 @@
module Awspec::Type
class Alb < ResourceBase
tags_allowed
def resource_via_client
@resource_via_client ||= find_alb(@display_name)
end
Expand Down Expand Up @@ -38,5 +39,13 @@ def has_subnet?(subnet_id)
subnet2 = find_subnet(subnet_id)
subnet2.subnet_id = subnet_id
end

def has_tag?(tag_key, tag_value)
alb_arn = resource_via_client.load_balancer_arn
tag_set = select_all_alb_tags(alb_arn)
tag_set.find do |tag|
tag.key == tag_key && tag.value == tag_value
end
end
end
end
1 change: 1 addition & 0 deletions spec/type/alb_spec.rb
Expand Up @@ -10,4 +10,5 @@
it { should have_subnet('subnet-1234a567') }
it { should have_subnet('my-subnet') }
it { should belong_to_vpc('my-vpc') }
it { should have_tag('environment').value('dev') }
end