Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Missing user_data key in digitalocean_host causes error #28

Open
lukebarton opened this issue Feb 16, 2016 · 1 comment
Open

Missing user_data key in digitalocean_host causes error #28

lukebarton opened this issue Feb 16, 2016 · 1 comment

Comments

@lukebarton
Copy link

ERROR: Inventory script (../terraform/support/terraform.py) had an execution error: Traceback (most recent call last):
  File "/opt/terraform/support/terraform.py", line 619, in <module>
    main()
  File "/opt/terraform/support/terraform.py", line 604, in main
    output = query_list(hosts)
  File "/opt/terraform/support/terraform.py", line 546, in query_list
    for name, attrs, hostgroups in hosts:
  File "/opt/terraform/support/terraform.py", line 67, in iterhosts
    yield parser(resource, module_name)
  File "/opt/terraform/support/terraform.py", line 83, in inner
    name, attrs, groups = func(*args, **kwargs)
  File "/opt/terraform/support/terraform.py", line 153, in digitalocean_host
    'metadata': json.loads(raw_attrs['user_data']),
KeyError: u'user_data'
@fquffio
Copy link

fquffio commented Mar 29, 2016

As I stated in a duplicate issue of this I opened by mistake, the following patch seems to solve this specific problem:

diff --git a/terraform.py b/terraform.py
index cab214d..bd53589 100755
--- a/terraform.py
+++ b/terraform.py
@@ -150,7 +150,7 @@ def digitalocean_host(resource, tfvars=None):
         'image': raw_attrs['image'],
         'ipv4_address': raw_attrs['ipv4_address'],
         'locked': parse_bool(raw_attrs['locked']),
-        'metadata': json.loads(raw_attrs['user_data']),
+        'metadata': json.loads(raw_attrs.get('user_data', '{}')),
         'region': raw_attrs['region'],
         'size': raw_attrs['size'],
         'ssh_keys': parse_list(raw_attrs, 'ssh_keys'),

Other issues might arise after applying this patch (for instance, I'm not sure about what could happen with a Cloud-Config script as a droplet's user data), so be very careful: I haven't tested it properly!

Cheers.

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

No branches or pull requests

2 participants