jfrog / terraform-provider-xray

Terraform provider to manage JFrog Xray
https://jfrog.com/xray/
Apache License 2.0
151 stars 12 forks source link

Import leading to 'Error looking up workspace' #117

Closed Nereis closed 1 year ago

Nereis commented 1 year ago

I'm trying to import a policy using from an existing deployment done manually with

terraform import xray_license_policy.test-lic test-lic

but I'm getting the following error

│ Error: Error looking up workspace
│ 
│ Invalid Terraform version: Malformed version: 

terraform apply commands with the same setup works fine if I rename the policy.

Requirements for and issue

Artifactory v7.55.8 / Xray 3.69.3 Terraform & provider version

Terraform v1.4.5
on linux_amd64
+ provider registry.terraform.io/jfrog/xray v1.12.

main.tf

terraform {
  required_providers {
    xray = {
      source  = "registry.terraform.io/jfrog/xray"
      version = "1.12.0"
    }
  }
}

terraform {
    backend "remote" {
        hostname      = "artifactory.somedomain"
        organization  = "somerepo_terraform_be"
        workspaces {
            name = "xray-dev"
        }
    }
}

provider "xray" {
  url          = "https://artifactory.somedomain/xray"
  access_token = var.ARTIFACTORY_TOKEN  
}

resource "xray_license_policy" "test-lic" {
  name        = "test-lic"
  description = "Managed by terraform"
  type        = "license"
  rule {
    name     = "aal"
    priority = 1
    actions {
      block_download {
        unscanned = false
        active    = false
      }
      custom_severity = "High"
      fail_build = false
      build_failure_grace_period_in_days = 0
    }
    criteria {
      allow_unknown           = true
      banned_licenses         = ["AAL"]
      multi_license_permissive = false
    }
  }
}

Logs

2023-04-18T14:15:40.418+0200 [INFO]  CLI command args: []string{"import", "xray_license_policy.test-lic", "test-lic"}
2023-04-18T14:15:40.421+0200 [TRACE] Meta.Backend: built configuration for "remote" backend with hash value 3925355522
2023-04-18T14:15:40.421+0200 [TRACE] Preserving existing state lineage "04656c7b-cf37-8b1c-66e0-b11379ad2e41"
2023-04-18T14:15:40.421+0200 [TRACE] Preserving existing state lineage "04656c7b-cf37-8b1c-66e0-b11379ad2e41"
2023-04-18T14:15:40.422+0200 [TRACE] Meta.Backend: working directory was previously initialized for "remote" backend
2023-04-18T14:15:40.422+0200 [TRACE] Meta.Backend: using already-initialized, unchanged "remote" backend configuration
2023-04-18T14:15:40.422+0200 [DEBUG] Service discovery for artifactory.somedomain at https://artifactory.somedomain/.well-known/terraform.json
2023-04-18T14:15:40.422+0200 [TRACE] HTTP client GET request to https://artifactory.somedomain/.well-known/terraform.json
2023-04-18T14:15:40.522+0200 [DEBUG] Service discovery for artifactory.somedomain aliased as localterraform.com
2023-04-18T14:15:40.631+0200 [TRACE] Meta.Backend: instantiated backend of type *remote.Remote
2023-04-18T14:15:40.632+0200 [TRACE] providercache.fillMetaCache: scanning directory .terraform/providers
2023-04-18T14:15:40.632+0200 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/jfrog/xray v1.12.0 for linux_amd64 at .terraform/providers/registry.terraform.io/jfrog/xray/1.12.0/linux_amd64
2023-04-18T14:15:40.632+0200 [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/jfrog/xray/1.12.0/linux_amd64 as a candidate package for registry.terraform.io/jfrog/xray 1.12.0
2023-04-18T14:15:40.691+0200 [DEBUG] checking for provisioner in "."
2023-04-18T14:15:40.691+0200 [DEBUG] checking for provisioner in "/home/linuxbrew/.linuxbrew/Cellar/terraform/1.4.5/bin"
2023-04-18T14:15:40.691+0200 [TRACE] Meta.Backend: backend *remote.Remote supports operations
2023-04-18T14:15:40.692+0200 [TRACE] backend/remote: looking up workspace for somerepo_terraform_be/xray-dev
╷
│ Error: Error looking up workspace
│ 
│ Invalid Terraform version: Malformed version: 
╵

Expected behavior Last Trace log indicates a path for the workspace at somerepo_terraform_be/xray-dev on Artifactory while the effective path on Artifactory is somerepo_terraform_be/workspaces/xray-dev/

danielmkn commented 1 year ago

@Nereis not sure this issue is related to the provider, but we will take a look.

Nereis commented 1 year ago

Same issue with the taint command

> terraform taint -allow-missing module.xray-common.xray_watch.ban-cl-strong 
│ Error: Error looking up workspace
│ 
│ Invalid Terraform version: Malformed version: 
Nereis commented 1 year ago

Solved, it was an issue with my state. The taint error lead me to this comment.

Not sure if it was exactly my issue but I completely wiped local terraform files and remote state which fix the issue. I don't know how I got there since I started everything last week...

Sorry for the inconvenience.