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

Aws Tags #190

Merged
merged 1 commit into from
May 12, 2015
Merged

Aws Tags #190

merged 1 commit into from
May 12, 2015

Conversation

wrightp
Copy link
Contributor

@wrightp wrightp commented Apr 22, 2015

Support tagging for AWS resources which are "taggable".

@wrightp
Copy link
Contributor Author

wrightp commented Apr 22, 2015

@tyler-ball this is ready for a review

@wrightp
Copy link
Contributor Author

wrightp commented Apr 22, 2015

@chef/ociv work re: aws tagging

@tyler-ball
Copy link
Contributor

The tag example is still failing like #189 correct?

action :allocate
end

aws_instance 'ref-machine-1' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm - I totally didn't think about the fact that most people are going to use machine and that doesn't support tag attributes. This solution (having to use aws_instance with the same name as the machine) seems less than intuitive. And I don't want to add a tag attribute to machine because that would require a new release of chef-provisioning... And whatever solution we use will have to work for machine, machine_batch and load_balancer.

Its not awesome, but I think we should read a tags field in the machine_options and load_balancer_options like so:

machine 'test' do
  machine_options bootstrap_options: {
    aws_tags: {'key' => 'value'}
  }
end
machine_batch 'test-batch' do
  machine_options bootstrap_options: {
    aws_tags: {'key' => 'value'}
  }
  machine 'test1'
  machine 'test2'
end
machine_image 'test-image' do
  machine_options bootstrap_options: {
    aws_tags: {'key' => 'value'}
  }
  image_options bootstrap_options: {
    aws_tags: {'key' => 'value'}
  }
end
load_balancer 'test_lb' do
  load_balancer_options aws_tags: {'key' => 'value'}
end

@jkeiser what do you think of this? Its a weird dual-user-interface problem, but I don't want to add a base provider_tags attribute to these resources in chef-provisioning because that implies all providers support tags.

Long term, I want to fix this by having machine in a recipe lookup the correct AwsInstance resource using the new resource mapping introduced in Chef 12. Then

machine 'ref-machine-1` do
  aws_tags :marco => 'polo'
end

would correctly instantiate a AwsInstance resource and apply the aws_tags to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm +1 on using *_options for instances and load balancers over how it is currently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd also like to add that even though tagging machines and load balancers isn't ideal with this branch, I would press that we still merge these changes pending a good review. This is a feature that is much needed and we can improve it in a new branch.

@wrightp
Copy link
Contributor Author

wrightp commented Apr 22, 2015

Yes, that's how I discovered it. The aws tag spec that tags an aws_instance is terminated properly. I was hoping it was some issue with the recipe I am overlooking.

@@ -221,6 +223,29 @@ def destroy_aws_object(obj)
raise NotImplementedError, :destroy_aws_object
end

# TODO documentation and tests
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add some yarddoc here?

@tyler-ball
Copy link
Contributor

The specs and the matcher look great! There is only a few missing specs I would like to see:

aws_ebs_volume 'ref' do
  aws_tags {'aaa' => 'a'}
end
aws_ebs_volume 'ref' do
  aws_tags {'bbb' => 'b'}
end

should only have the 'bbb' tag on it after convergence. This shows that deleting a tag by not putting it in the tag list works.

The other spec should test that when the aws_tags is missing we don't modify any of the current tags:

aws_ebs_volume 'ref' do
  aws_tags {'aaa' => 'a'}
end
aws_ebs_volume 'ref'

should still contain the tags 'aaa'

@wrightp
Copy link
Contributor Author

wrightp commented Apr 23, 2015

Good call on the tests. The first case I was handling, but the second case uncovered a bug where the tags were being wiped out because the default aws_tags attribute is {}. Since we may want that functionality I removed the default {} and handle the nil attribute in #converge_tags.

@tyler-ball
Copy link
Contributor

@Patrick-Wright you should be able to rebase against master and have your ref work!

@wrightp wrightp force-pushed the tags branch 2 times, most recently from ad99fc2 to 29af92d Compare April 24, 2015 16:56
@wrightp wrightp changed the title [WIP] Aws Tags Aws Tags May 11, 2015
@wrightp wrightp force-pushed the tags branch 2 times, most recently from a6914b7 to a24e55d Compare May 12, 2015 05:07
@tyler-ball
Copy link
Contributor

👍 Great job!

tyler-ball added a commit that referenced this pull request May 12, 2015
@tyler-ball tyler-ball merged commit 21ba3c5 into master May 12, 2015
@tyler-ball tyler-ball deleted the tags branch May 12, 2015 22:28
@lantrix lantrix mentioned this pull request May 19, 2015
@danieljimenez
Copy link

It doesn't seem to work on security groups when you use 'add_machine_options'

@wrightp
Copy link
Contributor Author

wrightp commented May 19, 2015

@danieljimenez you need to use the aws_tags attribute with the resource.

aws_security_group 'blah' do
  aws_tags :tag_name => 'value'
 # other attrs
end

the readme has some additional details: https://github.com/chef/chef-provisioning-aws#aws-resources

@danieljimenez
Copy link

@Patrick-Wright I did this:

add_machine_options aws_tags: { 'my-tag' => 'tag' }
... build machines ...
aws_security_group 'sg-12345'
   NoMethodError
    -------------
    undefined method `aws_tags' for Chef::Resource::AwsSecurityGroup

@wrightp
Copy link
Contributor Author

wrightp commented May 19, 2015

@danieljimenez good find.
@tyler-ball check this out: https://github.com/chef/chef-provisioning-aws/blob/master/lib/chef/resource/aws_security_group.rb#L1-L5

Looks like AwsSecurityGroup resource is requiring _with_entry, but is subclassing AWSResource. I'll try updating this locally, but do you see an immediate issue changing that to AWSResourceWithEntry?

@tyler-ball
Copy link
Contributor

@Patrick-Wright Ah! I updated security groups to subclass AWSResource instead of AWSResourceWithEntry in #194. I did this because the name of an aws security group is specific to a VPC, so we don't need to store a mapping entry.

It looks like this exposed an issue with tags! I'll file a bug.

@tyler-ball
Copy link
Contributor

Tracking this new issue in #204

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants