mitchellh/vagrant-google

'tags' only apply if zone explicitly set?

tracemeyers opened this issue · 4 comments

Do tags only apply if the zone is explicitly set?

This did not work (tags printed on the console was []:

google.tags = ['http-server', 'https-server']

but this did work (tags printed on the console was ["http-server", "https-server"]):

google.zone = "us-east1-b"                    
google.zone_config "us-east1-b" do |zone|     
    zone.tags = ['http-server', 'https-server']
end                                           

If that's the case, then this wasn't obvious to me so let me know the intended behavior.

@tracemeyers Thanks for submitting this issue.
Can you post full vagrantfiles for both cases? I want to check the rest of the config and try to repro this.

Note: please, make sure to obfuscate auth tokens and your project name.

@Temikus I experimented a bit more and found a few alternatives. It still would be interesting to know if my original script should have worked as expected or not.

The actual script performs common configuration and then configures each VM instance after that (this is how I do it for AWS and Azure). Moving the google.tags = ['http-server'] line from the common config to the VM specific config also resolved the issue. An easy change at least.

Here's the full script. I put your username on the relevant lines.

# Require the  provider plugin and YAML module                                  
require 'vagrant-google'                                                        
require 'yaml'                                                                  
                                                                                
# Read YAML file with instance information                                      
#instances = YAML.load_file(File.join(File.dirname(__FILE__), 'instances.yml')) 
                                                                                
# Specify Vagrant version and Vagrant API version                               
Vagrant.require_version '>= 1.6.0'                                              
VAGRANTFILE_API_VERSION = '2'                                                   
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'google'                                      
NAME_PREFIX = ENV['INSTANCE_NAME_PREFIX'] + "-"                                 
ni = ENV['NUM_INSTANCES'].to_i                                                  
                                                                                
# Create and configure the instance(s)                                          
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|                          
                                                                                
  # Use dummy box                                                               
  config.vm.box = "google/gce"                                                  
                                                                                
  # Configure default provider settings                                         
  config.vm.provider :google do |google, override|                              
    google.google_project_id = "redacted"                                       
    google.google_client_email = "redacted"                                     
    google.google_json_key_location = ENV['GOOGLE_JSON_KEY_FILE']               
    google.image = ENV['GOOGLE_IMAGE']                                          
    google.disk_size = 30                                                       
                                                                                
    # @Temikus - Does not work                                                  
    google.tags = ['http-server', 'https-server', 'postgresql-server']          
                                                                                
    # @Temikus - Works - Option 1                                               
    # https://github.com/mitchellh/vagrant-google/issues/189                    
    #google.zone = "us-east1-b"                                                 
    #google.zone_config "us-east1-b" do |zone|                                  
    #    zone.tags = ['http-server', 'https-server', 'postgresql-server']       
    #end                                                                        
                                                                                
  end # config.vm.provider 'google'                                             
  # Loop through YAML file and set per-instance information                     
  ni.times do |iter|                                                            
    config.vm.define NAME_PREFIX + iter.to_s do |srv|                           
                                                                                
      # Disable default shared folder                                           
      srv.vm.synced_folder '.', '/vagrant', disabled: true                      
                                                                                
      # Set per-instance provider configuration/overrides                       
      srv.vm.provider 'google' do |google, override|                            
                                                                                
        override.ssh.username = "redacted"                                      
        override.ssh.private_key_path = ENV['GOOGLE_PRIVKEY_FILE']              
        google.name = NAME_PREFIX + iter.to_s                                   
                                                                                
        # @Temikus - Works - Option 2                                           
        #google.tags = ['http-server', 'https-server', 'postgresql-server']     
                                                                                
      end # srv.vm.provider 'google'                                            
    end # config.vm.define                                                      
  end # ni.times                                                                
end # Vagrant.configure

@tracemeyers Thanks for providing the source files!

Unless you provided another set of tags in the zone-specific config, I think this may actually be a bug, due to the default value being nil instead of an empty array:

@service_accounts = UNSET_VALUE

Let me do some testing this week and see if it resolves it.

Ok, I've checked it out and it's not as simple as that, sadly :(

Seems like this is deeper in project->zonal config merge method and will require more debugging.
I'll try to take a closer look, but it'll likely take me a bit.