Skip to content

Commit

Permalink
feat: support ADO"
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollorion committed Oct 24, 2024
1 parent 0d2006c commit 0f707b5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
21 changes: 18 additions & 3 deletions spacemk/exporters/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(self, config: dict):
}

self.is_gitlab = False
self.is_ado = False
self.experimental_support_variable_sets = self._config.get("experimental_support_variable_sets", False)
if self.experimental_support_variable_sets:
logging.warning("Experimental support for variable sets is enabled")
Expand Down Expand Up @@ -1408,15 +1409,23 @@ def _map_contexts_data(self, src_data: dict) -> dict:
def _map_modules_data(self, src_data: dict) -> dict:
logging.info("Start mapping modules data")

vcs_provider = "gitlab" if self.is_gitlab else "github_custom"
vcs_provider = "github_custom"
if self.is_gitlab:
vcs_provider = "gitlab"
if self.is_ado:
vcs_provider = "azure_devops"

data = []
for module in src_data.get("modules"):
if self.is_gitlab and module.get("attributes.vcs-repo.identifier"):
segments = module.get("attributes.vcs-repo.identifier").split("/")
vcs_namespace = "/".join(segments[:-1])
vcs_repository = segments[-1]
elif not self.is_gitlab and module.get("attributes.vcs-repo.identifier"):
elif self.is_ado and module.get("attributes.vcs-repo.identifier"):
segments = module.get("attributes.vcs-repo.identifier").split("/")
vcs_namespace = segments[1]
vcs_repository = segments[3]
elif not self.is_gitlab and not self.is_ado and module.get("attributes.vcs-repo.identifier"):
segments = module.get("attributes.vcs-repo.identifier").split("/")
vcs_namespace = segments[0]
vcs_repository = segments[1]
Expand Down Expand Up @@ -1565,6 +1574,7 @@ def find_workspace_variable_with_invalid_name(data: dict, workspace_id: str, typ
"github_enterprise": "github_custom",
"bitbucket_server": "bitbucket_datacenter",
"gitlab_hosted": "gitlab",
"ado_services": "azure_devops",
}

if provider is None:
Expand All @@ -1581,7 +1591,12 @@ def find_workspace_variable_with_invalid_name(data: dict, workspace_id: str, typ
segments = workspace.get("attributes.vcs-repo.identifier").split("/")
vcs_namespace = "/".join(segments[:-1])
vcs_repository = segments[-1]
elif provider != "gitlab" and workspace.get("attributes.vcs-repo.identifier"):
elif provider == "azure_devops" and workspace.get("attributes.vcs-repo.identifier"):
self.is_ado = True
segments = workspace.get("attributes.vcs-repo.identifier").split("/")
vcs_namespace = segments[1]
vcs_repository = segments[3]
elif provider != "gitlab" and provider != "azure_devops" and workspace.get("attributes.vcs-repo.identifier"):
segments = workspace.get("attributes.vcs-repo.identifier").split("/")
vcs_namespace = segments[0]
vcs_repository = segments[1]
Expand Down
8 changes: 8 additions & 0 deletions spacemk/templates/base.tf.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ resource "spacelift_stack" "{{ stack._relationships.space._migration_id }}_{{ st
{{ argument("namespace", stack.vcs.namespace) }}
}
{% endif %}
{% elif stack.vcs.provider == "azure_devops" %}
azure_devops {
{{ argument("project", stack.vcs.namespace) }}
}
{% elif stack.vcs.provider %}
{{ stack.vcs.provider }} {
{{ argument("namespace", stack.vcs.namespace) }}
Expand Down Expand Up @@ -279,6 +283,10 @@ resource "spacelift_module" "{{ module._relationships.space._migration_id }}_{{
{{ argument("namespace", module.vcs.namespace) }}
}
{% endif %}
{% elif module.vcs.provider == "azure_devops" %}
azure_devops {
{{ argument("project", module.vcs.namespace) }}
}
{% elif module.vcs.provider %}
{{ module.vcs.provider }} {
{{ argument("namespace", module.vcs.namespace) }}
Expand Down

0 comments on commit 0f707b5

Please sign in to comment.