Skip to content

Commit

Permalink
fix: Translate stackscript_data to kwargs during disk creation (#488)
Browse files Browse the repository at this point in the history
* Translate stackscript_data to disk kwargs

* update test

* Address feedback
  • Loading branch information
lgarber-akamai authored Apr 1, 2024
1 parent 26987e7 commit 6e81059
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
17 changes: 8 additions & 9 deletions plugins/modules/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,15 +811,14 @@ def _delete_config_register(self, config: Config) -> None:
def _create_disk_register(self, **params: Any) -> None:
size = params.pop("size")

if params.get("stackscript_id") is not None:
params["stackscript"] = StackScript(
self.client, params.pop("stackscript_id")
)

# Workaround for an edge case where a StackScript has no UDFs
# and the API rejects an empty list for stackscript_data
if len(params.get("stackscript_data") or {}) < 1:
params.pop("stackscript_data")
stackscript_id = params.pop("stackscript_id", None)
if stackscript_id is not None:
params["stackscript"] = StackScript(self.client, stackscript_id)

# StackScript data is expected to be specified as kwargs
stackscript_data = params.pop("stackscript_data", None)
if stackscript_data is not None and isinstance(stackscript_data, dict):
params.update(stackscript_data)

# Workaround for race condition on implicit events
# See: TPT-2738
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
- "linode/alpine3.19"
script: |
#!/bin/ash
echo "cool stackscript"
# <UDF name="package" label="System Package to Install" example="nginx">
apk add $PACKAGE
state: present
register: stackscript_create

Expand All @@ -25,6 +26,8 @@
size: 1024
image: linode/alpine3.19
stackscript_id: "{{ stackscript_create.stackscript.id }}"
stackscript_data:
package: cowsay
state: present
register: instance_create

Expand Down

0 comments on commit 6e81059

Please sign in to comment.