From b774880b4c07bbe2e1dad36a14a5b774e6c3e2e2 Mon Sep 17 00:00:00 2001 From: apollorion Date: Mon, 5 Aug 2024 17:57:49 -0400 Subject: [PATCH] feat: make it easier to understand when/how to configure custom runner images --- config.yml.example | 5 +++++ spacemk/commands/generate.py | 4 +++- spacemk/templates/base.tf.jinja | 5 ++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/config.yml.example b/config.yml.example index 6e628b9..dc1491c 100644 --- a/config.yml.example +++ b/config.yml.example @@ -23,6 +23,11 @@ generator: # spacelift: # manage_state: true +# # Custom runner to use for stacks with custom runner images configured +# # See customizing the runner image: https://docs.spacelift.io/integrations/docker#customizing-the-runner-image +# # Default: N/A, must be provided (however, not always used. If it is used and not provided an exception will be raised during code generation) +# custom_runner_image: public.ecr.aws/spacelift/runner-terraform + extra_vars: foo: bar # "{{ extra_vars.foo }}" in a template will be replaced by "bar" diff --git a/spacemk/commands/generate.py b/spacemk/commands/generate.py index b8b4109..936f6a8 100644 --- a/spacemk/commands/generate.py +++ b/spacemk/commands/generate.py @@ -21,7 +21,9 @@ def default(value, _default): "manage_state": default(config.get("generator.spacelift.manage_state"), True) }, "github": { "custom_app": default(config.get("generator.github.custom_app"), False) - } + }, + "custom_runner_image": default(config.get("generator.custom_runner_image"), + "SPACELIFT_DEFAULT_INVALID"), } generator = Generator() diff --git a/spacemk/templates/base.tf.jinja b/spacemk/templates/base.tf.jinja index 1445198..f8a1831 100644 --- a/spacemk/templates/base.tf.jinja +++ b/spacemk/templates/base.tf.jinja @@ -95,7 +95,10 @@ resource "spacelift_stack" "{{ stack._relationships.space._migration_id }}_{{ st {% block stack_arguments_extra scoped %}{% endblock %} {% if stack.terraform.workflow_tool == "CUSTOM" %} - {{ argument("runner_image ", extra_vars.custom_terraform_runner_image ~ ":" ~ stack.terraform.version, required=True) }} + {% if generation_config.custom_runner_image == "SPACELIFT_DEFAULT_INVALID" %} + {% raise "generator.custom_runner_image is required for stacks with custom Terraform workflow tool." %} + {% endif %} + {{ argument("runner_image ", generation_config.custom_runner_image ~ ":" ~ stack.terraform.version, required=True) }} {% endif %} {% if stack.vcs.provider == "github_custom" %}