lib/build-cloud/subnet.rb in build-cloud-1.1.3 vs lib/build-cloud/subnet.rb in build-cloud-1.1.4
- old
+ new
@@ -34,17 +34,25 @@
require_one_of(:vpc_id, :vpc_name)
end
def create
-
- return if exists?
- @log.info( "Creating subnet for #{@options[:cidr_block]} ( #{@options[:name]} )" )
-
options = @options.dup
+ if exists?
+ # If exists update tags
+ if options[:tags]
+ create_tags(options[:tags])
+ end
+ return
+ end
+
+ return if exists?
+
+ @log.info( "Creating subnet for #{@options[:cidr_block]} ( #{options[:name]} )" )
+
unless options[:vpc_id]
options[:vpc_id] = BuildCloud::VPC.get_id_by_name( options[:vpc_name] )
options.delete(:vpc_name)
@@ -82,9 +90,18 @@
@log.info( "Subnet #{@options[:name]}" )
fog_object.destroy
+ end
+
+ def create_tags(tags)
+ # force symbols to strings in yaml tags
+ resolved_tags = fog_object.tag_set.dup.merge(tags.collect{|k,v| [k.to_s, v]}.to_h)
+ if resolved_tags != fog_object.tag_set
+ @log.info("Updating tags for subnet #{fog_object.subnet_id.to_s}")
+ @compute.create_tags( fog_object.subnet_id.to_s, tags )
+ end
end
end