Giter Site home page Giter Site logo

Better way to tag Instances about cfndsl HOT 4 CLOSED

cfndsl avatar cfndsl commented on August 20, 2024
Better way to tag Instances

from cfndsl.

Comments (4)

howech avatar howech commented on August 20, 2024

It turns out that for resource types that declare a Tags property, the Tag method gets defined automagically by the part that generates the various resource subclasses. Currently, only EC2::Instance, EC2::Volume and AutoScaling::AutoScalingGroup declare that they have a "Tags" property - cloudformation might now support some other resources that have tags.

To use the existing autogenerated functions you can do things like this:

Instance("Myinstance") {
  Tag {
    Key "Name"
    Value "MyInstance"
   }
  Tag {
    Key "Custom"
    Value "Blah blah bla"
   }
}

AutoScalingGroup("MyGroup") {
  Tag {
    Key "Name"
    Value "MyGroup"
    PropagateAtLaunch true
  }
  Tag {
    Key "Custom"
    Value "Blah blah bla"
    PropagateAtLaunch false
   }
}

This will generate an instance and an autoscaling group, each with two tags. One of the autoscaling group's tags will propagate to its instances, the other will not.

In cfndsl version 0.0.12, I added a function to the Resource class (ResourceDefintion) called addTag. It basically tries to call the Tag function if it is around, and only passes the PropagateAtLaunch if it is given.

Instance("Myinstance") {
  addTag( "Name", "MyInstance" )
  addTag( "Custom", "Blah blah blah")
}

AutoScalingGroup("MyGroup") {
  addTag( "Name", "MyGroup", true )
  addTag( "Custom", "Blah blah blah", false)
}

If you try to addTag to some resource that does not have a Tags property, cfndsl will fail trying to build the template.

from cfndsl.

liguorien avatar liguorien commented on August 20, 2024

Thank you very much!

from cfndsl.

josh-wrale avatar josh-wrale commented on August 20, 2024

This isn't working right now. If I add an addTag to an AWS::EC2::VPC resource, I get:

vagrant@vagrant-ubuntu-precise-64:/devops/assets/cfndsl/reference$ cfndsl reusable-vpc.rb
/var/lib/gems/1.9.1/gems/cfndsl-0.0.16/lib/cfndsl/Resources.rb:13: Undefined symbol: Tag()
/var/lib/gems/1.9.1/gems/cfndsl-0.0.16/lib/cfndsl/Resources.rb:13: Undefined symbol: Tag()
/var/lib/gems/1.9.1/gems/cfndsl-0.0.16/lib/cfndsl/Resources.rb:13: Undefined symbol: Tag()
vagrant@vagrant-ubuntu-precise-64:
/devops/assets/cfndsl/reference$

Perhaps, I'm doing something wrong?

from cfndsl.

josh-wrale avatar josh-wrale commented on August 20, 2024

Alright, so the issue is that the addTag approach doesn't work when structuring a VPC resource as follows:

This doesn't work:

  Resource("VPC" ) {
    Type "AWS::EC2::VPC"
    Property( "CidrBlock", Ref("VpcCidrBlock" )  ) 
    Property( "InstanceTenancy", Ref("VpcInstanceTenancy" ) )
    addTag( "Name", "Test")
  }

You must do this, whose syntax I incidentally like better:

  VPC("VPC") {
    CidrBlock Ref( "VpcCidrBlock" )
    InstanceTenancy Ref( "VpcInstanceTenancy" )
    addTag("Name", "Test")
  }

Awesome... I think the readme file led me into this trap. Please advise.

Thanks for this amazing tool!

-Joshua

from cfndsl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.