From 06eb9c30dd0aff21e05640874ebe168072069283 Mon Sep 17 00:00:00 2001 From: Ken Koch Date: Sun, 1 Oct 2017 07:32:33 -0400 Subject: [PATCH] Add support for tagging newly created DigitalOcean droplets. --- doc/topics/cloud/digitalocean.rst | 1 + salt/cloud/clouds/digitalocean.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/topics/cloud/digitalocean.rst b/doc/topics/cloud/digitalocean.rst index dd7c76d91f..129e1fcd3a 100644 --- a/doc/topics/cloud/digitalocean.rst +++ b/doc/topics/cloud/digitalocean.rst @@ -54,6 +54,7 @@ Set up an initial profile at ``/etc/salt/cloud.profiles`` or in the ipv6: True create_dns_record: True userdata_file: /etc/salt/cloud.userdata.d/setup + tags:tag1,tag2,tag3 Locations can be obtained using the ``--list-locations`` option for the ``salt-cloud`` command: diff --git a/salt/cloud/clouds/digitalocean.py b/salt/cloud/clouds/digitalocean.py index d5bcb4fb6f..0b9c088465 100644 --- a/salt/cloud/clouds/digitalocean.py +++ b/salt/cloud/clouds/digitalocean.py @@ -298,7 +298,8 @@ def create(vm_): 'size': get_size(vm_), 'image': get_image(vm_), 'region': get_location(vm_), - 'ssh_keys': [] + 'ssh_keys': [], + 'tags': [] } # backwards compat @@ -379,6 +380,13 @@ def create(vm_): raise SaltCloudConfigError("'ipv6' should be a boolean value.") kwargs['ipv6'] = ipv6 + tag_string = config.get_cloud_config_value( + 'tags', vm_, __opts__, search_global=False, default=False + ) + if tag_string: + for tag in tag_string.split(','): + kwargs['tags'].append(tag) + userdata_file = config.get_cloud_config_value( 'userdata_file', vm_, __opts__, search_global=False, default=None )