diff --git a/.gitignore b/.gitignore index 78aae93..ad6a40b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ terraform-provider-codefresh dist/ .vscode/ +**/__debug* **/.terraform **/terraform.tfstate diff --git a/codefresh/env.go b/codefresh/env.go index 3a53357..02c6c96 100644 --- a/codefresh/env.go +++ b/codefresh/env.go @@ -8,5 +8,5 @@ const ( ENV_CODEFRESH_API_KEY = "CODEFRESH_API_KEY" DEFAULT_CODEFRESH_API_URL = "https://g.codefresh.io/api" DEFAULT_CODEFRESH_API2_URL = "https://g.codefresh.io/2.0/api/graphql" - DEFAULT_CODEFRESH_PLUGIN_ADDR = "registry.terraform.io/-/codefresh" + DEFAULT_CODEFRESH_PLUGIN_ADDR = "registry.terraform.io/codefresh-io/codefresh" ) diff --git a/codefresh/resource_api_key.go b/codefresh/resource_api_key.go index 02fa573..da1637a 100644 --- a/codefresh/resource_api_key.go +++ b/codefresh/resource_api_key.go @@ -3,6 +3,7 @@ package codefresh import ( "errors" "fmt" + "strings" "github.com/codefresh-io/terraform-provider-codefresh/codefresh/cfclient" "github.com/codefresh-io/terraform-provider-codefresh/codefresh/internal/datautil" @@ -95,23 +96,8 @@ func resourceApiKeyCreate(d *schema.ResourceData, meta interface{}) error { client.Token = resp - apiKeys, err := client.GetApiKeysList() - if err != nil { - return nil - } - - var keyID string - for _, key := range apiKeys { - if key.Name == apiKey.Name { - keyID = key.ID - } - } - - if keyID == "" { - return errors.New("[ERROR] Key ID is not found.") - } - - d.SetId(keyID) + // Codefresh tokens are in the form xxxxxxxxxxxx.xxxxxxxxx the first half serves as the id + d.SetId(strings.Split(client.Token,".")[0]) return nil } @@ -132,7 +118,6 @@ func resourceApiKeyRead(d *schema.ResourceData, meta interface{}) error { return errors.New("[ERROR] Can't read API Key. Token is empty.") } - client.Token = token apiKey, err := client.GetAPIKey(keyID) if err != nil { @@ -157,8 +142,6 @@ func resourceApiKeyUpdate(d *schema.ResourceData, meta interface{}) error { return errors.New("[ERROR] Can't read API Key. Token is empty.") } - client.Token = token - err := client.UpdateAPIKey(&apiKey) if err != nil { return err diff --git a/main.go b/main.go index ac8ab33..f1e039d 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ func main() { providerAddr = codefresh.DEFAULT_CODEFRESH_PLUGIN_ADDR } plugin.Serve(&plugin.ServeOpts{ + ProviderAddr: providerAddr, ProviderFunc: codefresh.Provider, Debug: debugMode, })