From d949bd230a4af3d259c391bdae89116cb6d6fee6 Mon Sep 17 00:00:00 2001 From: apollorion Date: Mon, 21 Oct 2024 15:22:04 -0400 Subject: [PATCH] feat: add a migrated_from label so we can know where resources were migrated from --- spacemk/exporters/base.py | 1 + spacemk/templates/base.tf.jinja | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/spacemk/exporters/base.py b/spacemk/exporters/base.py index 6cad658..e158eec 100644 --- a/spacemk/exporters/base.py +++ b/spacemk/exporters/base.py @@ -199,6 +199,7 @@ def export(self) -> None: data = self._filter_data(data) data = self._enrich_data(data) data = self._map_data(data) + data["class"] = type(self).__name__ save_normalized_data(data) logging.info("Stop exporting data") diff --git a/spacemk/templates/base.tf.jinja b/spacemk/templates/base.tf.jinja index c0a45d1..50e1e2a 100644 --- a/spacemk/templates/base.tf.jinja +++ b/spacemk/templates/base.tf.jinja @@ -21,6 +21,7 @@ resource "spacelift_space" "{{ space._migration_id }}" { {{ argument("inherit_entities", True, default=False) }} {{ argument("name", space.name, required=True) }} {{ argument("parent_space_id", "root", required=True) }} + {{ argument("labels", ["migration_class:" + class]) }} {% block space_arguments_extra scoped %}{% endblock %} } @@ -28,6 +29,7 @@ resource "spacelift_space" "{{ space._migration_id }}" { resource "spacelift_context" "{{ space._migration_id }}_terraform_workflow_tool" { {{ argument("description", "Allows to use custom versions of Terraform. Make sure to provide the Terraform binary in the custom runner image for the stack.") }} {{ argument("name", "Terraform Workflow Tool", required=True) }} + {{ argument("labels", ["migration_class:" + class]) }} } resource "spacelift_mounted_file" "workflow" { @@ -83,7 +85,7 @@ resource "spacelift_stack" "{{ stack._relationships.space._migration_id }}_{{ st {{ argument("branch", stack.vcs.branch, required=True) }} {{ argument("description", stack.description) }} {{ argument("local_preview", stack.local_preview) }} - {{ argument("labels", stack.labels) }} + {{ argument("labels", ["migration_class:" + class] + stack.labels|default([])) }} {{ argument("manage_state", generation_config.spacelift.manage_state) }} {{ argument("name", stack.name, required=True) }} {{ argument("project_root", stack.vcs.project_root) }} @@ -197,7 +199,7 @@ resource "spacelift_environment_variable" "{{ variable._relationships.space._mig {% for context in contexts %} resource "spacelift_context" "{{ context._relationships.space._migration_id }}_{{ context._migration_id }}" { {{ argument("description", context.description) }} - {{ argument("labels", context.labels, default=[]) }} + {{ argument("labels", ["migration_class:" + class] + context.labels) }} {{ argument("name", context.name, required=True) }} {% block context_arguments_extra scoped %}{% endblock %} } @@ -268,6 +270,7 @@ resource "spacelift_module" "{{ module._relationships.space._migration_id }}_{{ {{ argument("repository", module.vcs.repository, required=True) }} {{ argument("space_id", "spacelift_space." ~ module._relationships.space._migration_id ~ ".id", serialize=False) }} {{ argument("terraform_provider", module.terraform_provider) }} + {{ argument("labels", ["migration_class:" + class]) }} {% block module_arguments_extra scoped %}{% endblock %} {% if module.vcs.provider == "github_custom" %}