Skip to content

Commit

Permalink
Better handle older TFE versions
Browse files Browse the repository at this point in the history
  • Loading branch information
jmfontaine committed May 26, 2024
1 parent 4858daf commit fc0e53f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions spacemk/exporters/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def _extract_data(self) -> list[dict]:
data["providers"].extend(self._extract_providers_data(organization))
data["tasks"].extend(self._extract_tasks_data(organization))
data["teams"].extend(self._extract_teams_data(organization))
# data["variable_sets"].extend(self._extract_variable_sets_data(organization))
data["variable_sets"].extend(self._extract_variable_sets_data(organization))
data["workspaces"].extend(self._extract_workspaces_data(organization))

# for variable_set in data.variable_sets:
Expand Down Expand Up @@ -621,6 +621,10 @@ def _extract_data_from_api(
if raw_datum.get("attributes.name") and include_regex.match(raw_datum.get("attributes.name")) is None:
continue

# KLUDGE: Workspace variables do not have a 'name' attribute but use 'key' instead
if raw_datum.get("attributes.key") and include_regex.match(raw_datum.get("attributes.key")) is None:
continue

if properties:
# KLUDGE: There must be a cleaner way to handle this
datum = benedict()
Expand Down Expand Up @@ -1191,6 +1195,7 @@ def find_workspace(data: dict, workspace_id: str) -> dict:
continue

workspace = find_workspace(data=src_data, workspace_id=workspace_id)

if workspace is None:
logging.warning(
f"Could not find workspace '{workspace_id}' for variable '{variable.get('id')}'. Skipping."
Expand Down Expand Up @@ -1291,10 +1296,15 @@ def find_workspace_variable_with_invalid_name(data: dict, workspace_id: str, typ
else:
terraform_workflow_tool = "TERRAFORM_FOSS"

if "relationships.project.data.id" in workspace:
if workspace.get("relationships.project.data.id") is not None:
space_id = workspace.get("relationships.project.data.id")
else:
logging.info(f"Workspace '{workspace.get('attributes.name')}' is attached to a project")
elif workspace.get("relationships.organization.data.id") is not None:
space_id = workspace.get("relationships.organization.data.id")
logging.info(f"Workspace '{workspace.get('attributes.name')}' is attached to an organization")
else:
space_id = None
logging.warning(f"Workspace '{workspace.get('attributes.name')}' has no space")

data.append(
{
Expand Down

0 comments on commit fc0e53f

Please sign in to comment.