env0 / env0-migration-tool

A repository that contains the necessary files in order to import existing Terraform workspaces from other platforms
1 stars 2 forks source link

Bug - Cannot migrate workspace from terraform cloud to env0 #17

Open zi-amatzia opened 6 months ago

zi-amatzia commented 6 months ago

Hi While running the migration tool i got the following error

╷
│ Error: Invalid object key
│
│   on parse_projects.tf line 8, in locals:
│    7:   project_ids_to_names = {
│    8:     for id in local.project_ids : id =>
│    9:     contains(keys(local.projects_response_as_map), id) ? local.projects_response_as_map[id] : id
│   10:   }
│
│ Key expression in 'for' expression must not produce a null value.

It seems its looking for a project id. Our organization does not have any project configured in terraform cloud so project id returns a null response and fails the migration. To resolve this we made 2 changes

  1. parse_projects.tf line 2 - 3 we changed to projects_url_response_json = jsondecode(data.http.projects.response_body)["data"] projects_url_response = local.projects_url_response_json == null ? [{id="my-org",attributes={name="default"}}] : local.projects_url_response_json
  2. line 7 to project_ids = toset([for workspace in data.tfe_workspace.all : coalesce(workspace.project_id,"my-org")])
  3. parse_workspaces.tf line 19 project_name = local.project_ids_to_names[coalesce(data.tfe_workspace.all[name].project_id, "zoominfo")]

Also in env0-resources-generator -> terraform_templates -> environments.tftpl it always assumes in repository that you are using https://www.github.com.... but if you use an enterprise git you might have a different url