diff --git a/.changelog/1022.txt b/.changelog/1022.txt new file mode 100644 index 000000000..658b543bd --- /dev/null +++ b/.changelog/1022.txt @@ -0,0 +1,3 @@ +```release-note:fix +Improve error handling for gitops, recreate resource if exists in terraform state but deleted outside of terraform flow. +``` diff --git a/go.mod b/go.mod index e26f20bbb..13968fd17 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/antihax/optional v1.0.0 github.com/aws/aws-sdk-go v1.46.4 github.com/docker/docker v24.0.5+incompatible - github.com/harness/harness-go-sdk v0.4.1 + github.com/harness/harness-go-sdk v0.4.3 github.com/harness/harness-openapi-go-client v0.0.21 github.com/hashicorp/go-cleanhttp v0.5.2 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 @@ -15,6 +15,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.8.1 + google.golang.org/grpc v1.61.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -80,7 +81,6 @@ require ( golang.org/x/tools v0.19.0 // indirect google.golang.org/appengine v1.6.8 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect - google.golang.org/grpc v1.61.0 // indirect google.golang.org/protobuf v1.32.0 // indirect gotest.tools/v3 v3.3.0 // indirect ) diff --git a/go.sum b/go.sum index b22e324eb..062d5c688 100644 --- a/go.sum +++ b/go.sum @@ -54,8 +54,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/harness/harness-go-sdk v0.4.1 h1:T42mXbfJDkZrroY79pzN8MolDcDhvHje0EpgeRjv+pY= -github.com/harness/harness-go-sdk v0.4.1/go.mod h1:a/1HYTgVEuNEoh3Z3IsOHZdlUNxl94KcX57ZSNVGll0= +github.com/harness/harness-go-sdk v0.4.3 h1:lAyQT7paCayYIOPrZPmCHOtG2uWCgUHugcaN9MJtYnE= +github.com/harness/harness-go-sdk v0.4.3/go.mod h1:a/1HYTgVEuNEoh3Z3IsOHZdlUNxl94KcX57ZSNVGll0= github.com/harness/harness-openapi-go-client v0.0.21 h1:VtJnpQKZvCAlaCmUPbNR69OT3c5WRdhNN5TOgUwtwZ4= github.com/harness/harness-openapi-go-client v0.0.21/go.mod h1:u0vqYb994BJGotmEwJevF4L3BNAdU9i8ui2d22gmLPA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= diff --git a/helpers/errors.go b/helpers/errors.go index 48323d021..2bd255c17 100644 --- a/helpers/errors.go +++ b/helpers/errors.go @@ -2,61 +2,18 @@ package helpers import ( "encoding/json" + "github.com/harness/harness-go-sdk/harness/nextgen" + openapi_client_nextgen "github.com/harness/harness-openapi-go-client/nextgen" + "google.golang.org/grpc/codes" "net/http" "github.com/harness/harness-go-sdk/harness/dbops" - "github.com/harness/harness-go-sdk/harness/nextgen" - openapi_client_nextgen "github.com/harness/harness-openapi-go-client/nextgen" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func HandleApiError(err error, d *schema.ResourceData, httpResp *http.Response) diag.Diagnostics { - erro, ok := err.(nextgen.GenericSwaggerError) - if ok { - if httpResp != nil && httpResp.StatusCode == 401 { - return diag.Errorf(httpResp.Status + "\n" + "Hint:\n" + - "1) Please check if token has expired or is wrong.\n" + - "2) Harness Provider is misconfigured. For firstgen resources please give the correct api_key and for nextgen resources please give the correct platform_api_key.") - } - if httpResp != nil && httpResp.StatusCode == 403 { - return diag.Errorf(httpResp.Status + "\n" + "Hint:\n" + - "1) Please check if the token has required permission for this operation.\n" + - "2) Please check if the token has expired or is wrong.") - } - if httpResp != nil && httpResp.StatusCode == 404 { - return diag.Errorf("resource with ID %s not found: %v", d.Id(), erro.Error()) - } - return diag.Errorf(erro.Error()) - } - - err_openapi_client, ok := err.(openapi_client_nextgen.GenericSwaggerError) - if ok { - if httpResp != nil && httpResp.StatusCode == 401 { - return diag.Errorf(httpResp.Status + "\n" + "Hint:\n" + - "1) Please check if token has expired or is wrong.\n" + - "2) Harness Provider is misconfigured. For firstgen resources please give the correct api_key and for nextgen resources please give the correct platform_api_key.") - } - - if httpResp != nil && httpResp.StatusCode == 403 { - return diag.Errorf(httpResp.Status + "\n" + "Hint:\n" + - "1) Please check if the token has required permission for this operation.\n" + - "2) Please check if the token has expired or is wrong.") - } - - if httpResp != nil && httpResp.StatusCode == 404 { - return diag.Errorf("resource with ID %s not found: %v", d.Id(), erro.Error()) - } - - var jsonMap map[string]interface{} - err := json.Unmarshal(err_openapi_client.Body(), &jsonMap) - if err == nil { - return diag.Errorf(jsonMap["message"].(string)) - } - return diag.Errorf(err_openapi_client.Error()) - } - - return diag.Errorf(err.Error()) + return handleApiError(err, d, httpResp, false) } func HandleDBOpsApiError(err error, d *schema.ResourceData, httpResp *http.Response) diag.Diagnostics { @@ -80,28 +37,52 @@ func HandleDBOpsApiError(err error, d *schema.ResourceData, httpResp *http.Respo return diag.Errorf(err.Error()) } -func HandleReadApiError(err error, d *schema.ResourceData, httpResp *http.Response) diag.Diagnostics { +func handleApiError(err error, d *schema.ResourceData, httpResp *http.Response, read bool) diag.Diagnostics { erro, ok := err.(nextgen.GenericSwaggerError) if ok { + errMessage := erro.Error() + gitopsErr, gitopsErrOk := erro.Model().(nextgen.GatewayruntimeError) + if gitopsErrOk { + errMessage = gitopsErr.Message + } + if httpResp != nil && httpResp.StatusCode == 401 { - return diag.Errorf(httpResp.Status + "\n" + "Hint:\n" + - "1) Please check if token has expired or is wrong.\n" + + return diag.Errorf("%s", httpResp.Status+"\n"+"Hint:\n"+ + "1) Please check if token has expired or is wrong.\n"+ "2) Harness Provider is misconfigured. For firstgen resources please give the correct api_key and for nextgen resources please give the correct platform_api_key.") } + if gitopsErrOk && httpResp != nil && httpResp.StatusCode == 403 { + if len(errMessage) > 0 { + return diag.Errorf("%s", httpResp.Status+"\n"+"Hint:\n"+ + "1) Please check if the token has required permission for this operation.\n"+ + "2) Please check if the token has expired or is wrong.\n"+ + "3) "+errMessage) + } + } if httpResp != nil && httpResp.StatusCode == 403 { - return diag.Errorf(httpResp.Status + "\n" + "Hint:\n" + - "1) Please check if the token has required permission for this operation.\n" + + return diag.Errorf("%s", httpResp.Status+"\n"+"Hint:\n"+ + "1) Please check if the token has required permission for this operation.\n"+ "2) Please check if the token has expired or is wrong.") } if httpResp != nil && httpResp.StatusCode == 404 { - return diag.Errorf("resource with ID %s not found: %v", d.Id(), erro.Error()) - } - if erro.Model() != nil && (erro.Code() == nextgen.ErrorCodes.ResourceNotFound || erro.Code() == nextgen.ErrorCodes.EntityNotFound) { - d.SetId("") - d.MarkNewResource() - return nil - } - return diag.Errorf(erro.Error()) + // GitOps handling for NotFound + if gitopsErrOk && read { + if codes.Code(gitopsErr.Code) == codes.NotFound { + d.SetId("") + d.MarkNewResource() + return nil + } + } + return diag.Errorf("resource with ID %s not found: %v", d.Id(), errMessage) + } + if read && !gitopsErrOk { + if erro.Model() != nil && (erro.Code() == nextgen.ErrorCodes.ResourceNotFound || erro.Code() == nextgen.ErrorCodes.EntityNotFound) { + d.SetId("") + d.MarkNewResource() + return nil + } + } + return diag.Errorf(errMessage) } err_openapi_client, ok := err.(openapi_client_nextgen.GenericSwaggerError) @@ -130,6 +111,10 @@ func HandleReadApiError(err error, d *schema.ResourceData, httpResp *http.Respon return diag.Errorf(err.Error()) } +func HandleReadApiError(err error, d *schema.ResourceData, httpResp *http.Response) diag.Diagnostics { + return handleApiError(err, d, httpResp, true) +} + func HandleDBOpsReadApiError(err error, d *schema.ResourceData, httpResp *http.Response) diag.Diagnostics { _, ok := err.(dbops.GenericSwaggerError) if ok && httpResp != nil { diff --git a/internal/service/platform/gitops/agent/resource_gitops_agent.go b/internal/service/platform/gitops/agent/resource_gitops_agent.go index 76cc9d284..9a67ea774 100644 --- a/internal/service/platform/gitops/agent/resource_gitops_agent.go +++ b/internal/service/platform/gitops/agent/resource_gitops_agent.go @@ -113,7 +113,7 @@ func resourceGitopsAgentCreate(ctx context.Context, d *schema.ResourceData, meta resp, httpResp, err := c.AgentApi.AgentServiceForServerCreate(ctx, *createAgentRequest) if err != nil { - return helpers.HandleApiError(err, d, httpResp) + return helpers.HandleReadApiError(err, d, httpResp) } // Soft delete lookup error handling // https://harness.atlassian.net/browse/PL-23765 @@ -155,9 +155,54 @@ func resourceGitopsAgentRead(ctx context.Context, d *schema.ResourceData, meta i } func resourceGitopsAgentUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) ctx = context.WithValue(ctx, nextgen.ContextAccessToken, hh.EnvVars.BearerToken.Get()) + + var e diag.Diagnostics + if d.HasChange("identifier") { + oldValue, newValue := d.GetChange("identifier") + if oldValue != "" && oldValue != newValue { + e = append(e, diag.Errorf("%s", "Field 'identifier' cannot be updated after creation.")[0]) + } + if err := d.Set("identifier", oldValue); err != nil { + return diag.FromErr(err) + } + } + + if d.HasChange("account_id") { + oldValue, newValue := d.GetChange("account_id") + if oldValue != "" && oldValue != newValue { + e = append(e, diag.Errorf("%s", "Field 'account_id' cannot be updated after creation.")[0]) + } + if err := d.Set("account_id", oldValue); err != nil { + return diag.FromErr(err) + } + } + + if d.HasChange("org_id") { + oldValue, newValue := d.GetChange("org_id") + if oldValue != "" && oldValue != newValue { + e = append(e, diag.Errorf("%s", "Field 'org_id' cannot be updated after creation.")[0]) + } + if err := d.Set("org_id", oldValue); err != nil { + return diag.FromErr(err) + } + } + + if d.HasChange("project_id") { + oldValue, newValue := d.GetChange("project_id") + if oldValue != "" && oldValue != newValue { + e = append(e, diag.Errorf("%s", "Field 'project_id' cannot be updated after creation.")[0]) + } + if err := d.Set("project_id", oldValue); err != nil { + return diag.FromErr(err) + } + } + + if len(e) > 0 { + return e + } + agentIdentifier := d.Get("identifier").(string) updateAgentRequest := buildCreateUpdateAgentRequest(d) updateAgentRequest.AccountIdentifier = c.AccountId diff --git a/internal/service/platform/gitops/app_project/resource_gitops_app_project_mapping.go b/internal/service/platform/gitops/app_project/resource_gitops_app_project_mapping.go index 3a2cdcf33..7846c2639 100644 --- a/internal/service/platform/gitops/app_project/resource_gitops_app_project_mapping.go +++ b/internal/service/platform/gitops/app_project/resource_gitops_app_project_mapping.go @@ -26,6 +26,7 @@ func ResourceGitopsAppProjectMapping() *schema.Resource { Description: "Account identifier of the GitOps agent's Application Project.", Type: schema.TypeString, Required: true, + ForceNew: true, }, "org_id": { Description: "Organization identifier of the GitOps agent's Application Project.", @@ -41,6 +42,7 @@ func ResourceGitopsAppProjectMapping() *schema.Resource { Description: "Agent identifier for which the ArgoCD and Harness project mapping is to be created.", Type: schema.TypeString, Required: true, + ForceNew: true, }, "identifier": { Description: "Identifier of the GitOps Application Project.", @@ -51,6 +53,7 @@ func ResourceGitopsAppProjectMapping() *schema.Resource { Description: "ArgoCD Project name which is to be mapped to the Harness project.", Type: schema.TypeString, Required: true, + ForceNew: true, }, }, } @@ -65,7 +68,7 @@ func resourceGitopsAppProjectMappingCreate(ctx context.Context, d *schema.Resour resp, httpResp, err := c.ProjectMappingsApi.AppProjectMappingServiceCreateV2(ctx, *createAppProjectMappingRequest, agentIdentifier) if err != nil { - return helpers.HandleApiError(err, d, httpResp) + return helpers.HandleReadApiError(err, d, httpResp) } if &resp == nil { diff --git a/internal/service/platform/gitops/applications/resource_gitops_applications.go b/internal/service/platform/gitops/applications/resource_gitops_applications.go index d94aee361..b16b1d577 100644 --- a/internal/service/platform/gitops/applications/resource_gitops_applications.go +++ b/internal/service/platform/gitops/applications/resource_gitops_applications.go @@ -740,7 +740,7 @@ func resourceGitopsApplicationRead(ctx context.Context, d *schema.ResourceData, QueryRepo: optional.NewString(repoIdentifier), }) if err != nil { - return helpers.HandleApiError(err, d, httpResp) + return helpers.HandleReadApiError(err, d, httpResp) } // Soft delete lookup error handling @@ -760,6 +760,23 @@ func resourceGitopsApplicationUpdate(ctx context.Context, d *schema.ResourceData updateApplicationRequest := buildUpdateApplicationRequest(d) var agentIdentifier, orgIdentifier, projectIdentifier, clusterIdentifier, repoIdentifier, appMetaDataName string var skipRepoValidation bool + + if d.HasChange("agent_id") { + return diag.Errorf("%s", "Field 'agent_id' cannot be updated after creation.") + } + if d.HasChange("account_id") { + return diag.Errorf("%s", "Field 'project_id' cannot be updated after creation.") + } + if d.HasChange("account_id") { + return diag.Errorf("%s", "Field 'account_id' cannot be updated after creation.") + } + if d.HasChange("org_id") { + return diag.Errorf("%s", "Field 'org_id' cannot be updated after creation.") + } + if d.HasChange("project_id") { + return diag.Errorf("%s", "Field 'project_id' cannot be updated after creation.") + } + if attr, ok := d.GetOk("agent_id"); ok { agentIdentifier = attr.(string) } diff --git a/internal/service/platform/gitops/cluster/resource_gitops_cluster.go b/internal/service/platform/gitops/cluster/resource_gitops_cluster.go index eea57369f..30156ec88 100644 --- a/internal/service/platform/gitops/cluster/resource_gitops_cluster.go +++ b/internal/service/platform/gitops/cluster/resource_gitops_cluster.go @@ -27,26 +27,31 @@ func ResourceGitopsCluster() *schema.Resource { Description: "Account identifier of the GitOps cluster.", Type: schema.TypeString, Required: true, + ForceNew: true, }, "project_id": { Description: "Project identifier of the GitOps cluster.", Type: schema.TypeString, Optional: true, + ForceNew: true, }, "org_id": { Description: "Organization identifier of the cluster.", Type: schema.TypeString, Optional: true, + ForceNew: true, }, "agent_id": { Description: "Agent identifier of the GitOps cluster.", Type: schema.TypeString, Required: true, + ForceNew: true, }, "identifier": { Description: "Identifier of the GitOps cluster.", Type: schema.TypeString, Required: true, + ForceNew: true, }, "request": { Description: "Cluster create or update request.", @@ -111,6 +116,7 @@ func ResourceGitopsCluster() *schema.Resource { "bearer_token": { Description: "Bearer authentication token the cluster.", Type: schema.TypeString, + Sensitive: true, Optional: true, }, "tls_client_config": { @@ -420,7 +426,7 @@ func resourceGitopsClusterRead(ctx context.Context, d *schema.ResourceData, meta }) if err != nil { - return helpers.HandleApiError(err, d, httpResp) + return helpers.HandleReadApiError(err, d, httpResp) } // Soft delete lookup error handling @@ -435,9 +441,9 @@ func resourceGitopsClusterRead(ctx context.Context, d *schema.ResourceData, meta } func resourceGitopsClusterUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) ctx = context.WithValue(ctx, nextgen.ContextAccessToken, hh.EnvVars.BearerToken.Get()) + agentIdentifier := d.Get("agent_id").(string) identifier := d.Get("identifier").(string) updateClusterRequest := buildUpdateClusterRequest(d) diff --git a/internal/service/platform/gitops/gnupg/resource_gnupg.go b/internal/service/platform/gitops/gnupg/resource_gnupg.go index c87bea0b6..3a43e1c2a 100644 --- a/internal/service/platform/gitops/gnupg/resource_gnupg.go +++ b/internal/service/platform/gitops/gnupg/resource_gnupg.go @@ -164,7 +164,7 @@ func resourceGitopsGnupgRead(ctx context.Context, d *schema.ResourceData, meta i }) if err != nil { - return helpers.HandleApiError(err, d, httpResp) + return helpers.HandleReadApiError(err, d, httpResp) } // Soft delete lookup error handling diff --git a/internal/service/platform/gitops/project/resource_gitops_app_project.go b/internal/service/platform/gitops/project/resource_gitops_app_project.go index 7d317e6c0..7c315a410 100644 --- a/internal/service/platform/gitops/project/resource_gitops_app_project.go +++ b/internal/service/platform/gitops/project/resource_gitops_app_project.go @@ -21,24 +21,28 @@ func ResourceProject() *schema.Resource { Importer: helpers.GitopsAgentProjectImporter, Schema: map[string]*schema.Schema{ "agent_id": { - Description: "Agent identifier of the GitOps project.", + Description: "Agent identifier of the GitOps project. Project is created on agent scope.", Type: schema.TypeString, Required: true, + ForceNew: true, }, "account_id": { - Description: "Account identifier of the GitOps project.", + Description: "Account identifier of the GitOps project/agent.", Type: schema.TypeString, Required: true, + ForceNew: true, }, "org_id": { - Description: "Org identifier of the GitOps project.", + Description: "Org identifier of the GitOps agent for which project is created.", Type: schema.TypeString, Optional: true, + ForceNew: true, }, "project_id": { - Description: "Project identifier of the GitOps repository.", + Description: "Project identifier of the GitOps agent for which project is created.", Type: schema.TypeString, Optional: true, + ForceNew: true, }, "query_name": { Description: "Identifier for the GitOps project.", @@ -47,7 +51,7 @@ func ResourceProject() *schema.Resource { Computed: true, }, "upsert": { - Description: "Indicates if the GitOps repository should be updated if existing and inserted if not.", + Description: "Indicates if the GitOps project should be updated if existing and inserted if not.", Type: schema.TypeBool, Optional: true, }, @@ -71,7 +75,7 @@ func ResourceProject() *schema.Resource { "namespace": { Type: schema.TypeString, Optional: true, - Description: "Namespace of the GitOps project.", + Description: "Namespace of the GitOps project. This must match agent namespace.", }, "resource_version": { Type: schema.TypeString, @@ -588,7 +592,7 @@ func resourceProjectUpdate(ctx context.Context, d *schema.ResourceData, meta int }) if err != nil { - return helpers.HandleApiError(err, d, httpResp) + return helpers.HandleReadApiError(err, d, httpResp) } // Soft delete lookup error handling // https://harness.atlassian.net/browse/PL-23765 diff --git a/internal/service/platform/gitops/repository/data_source_gitops_repository.go b/internal/service/platform/gitops/repository/data_source_gitops_repository.go index ee162be4a..30b2b3262 100644 --- a/internal/service/platform/gitops/repository/data_source_gitops_repository.go +++ b/internal/service/platform/gitops/repository/data_source_gitops_repository.go @@ -8,6 +8,7 @@ import ( "github.com/harness/terraform-provider-harness/internal" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) func DataSourceGitopsRepository() *schema.Resource { @@ -94,10 +95,11 @@ func DataSourceGitopsRepository() *schema.Resource { Optional: true, }, "type_": { - Description: "Type specifies the type of the repo. Can be either \"git\" or \"helm. \"git\" is assumed if empty or absent.", - Type: schema.TypeString, - Optional: true, - Computed: true, + Description: "Type specifies the type of the repo. Can be either \"git\" or \"helm. \"git\" is assumed if empty or absent.", + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{"git", "helm"}, false), }, "name": { Description: "Name to be used for this repo. Only used with Helm repos.", diff --git a/internal/service/platform/gitops/repository/resource_gitops_repository.go b/internal/service/platform/gitops/repository/resource_gitops_repository.go index abbb2e3c8..716194d8a 100644 --- a/internal/service/platform/gitops/repository/resource_gitops_repository.go +++ b/internal/service/platform/gitops/repository/resource_gitops_repository.go @@ -2,6 +2,7 @@ package repository import ( "context" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/antihax/optional" hh "github.com/harness/harness-go-sdk/harness/helpers" @@ -26,26 +27,31 @@ func ResourceGitopsRepositories() *schema.Resource { Description: "Account identifier of the GitOps repository.", Type: schema.TypeString, Required: true, + ForceNew: true, }, "project_id": { Description: "Project identifier of the GitOps repository.", Type: schema.TypeString, Optional: true, + ForceNew: true, }, "org_id": { Description: "Organization identifier of the GitOps repository.", Type: schema.TypeString, Optional: true, + ForceNew: true, }, "agent_id": { Description: "Agent identifier of the GitOps repository.", Type: schema.TypeString, Required: true, + ForceNew: true, }, "identifier": { Description: "Identifier of the GitOps repository.", Type: schema.TypeString, Required: true, + ForceNew: true, }, "repo": { Description: "Repo details holding application configurations.", @@ -99,10 +105,11 @@ func ResourceGitopsRepositories() *schema.Resource { Optional: true, }, "type_": { - Description: "Type specifies the type of the repo. Can be either \"git\" or \"helm. \"git\" is assumed if empty or absent.", - Type: schema.TypeString, - Optional: true, - Computed: true, + Description: "Type specifies the type of the repo. Can be either \"git\" or \"helm. \"git\" is assumed if empty or absent.", + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{"git", "helm"}, false), }, "name": { Description: "Name to be used for this repo. Only used with Helm repos.", @@ -402,7 +409,7 @@ func resourceGitOpsRepositoryRead(ctx context.Context, d *schema.ResourceData, m }) if err != nil { - return helpers.HandleApiError(err, d, httpResp) + return helpers.HandleReadApiError(err, d, httpResp) } // Soft delete lookup error handling // https://harness.atlassian.net/browse/PL-23765 @@ -419,6 +426,7 @@ func resourceGitOpsRepositoryRead(ctx context.Context, d *schema.ResourceData, m func resourceGitOpsRepositoryUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) var orgIdentifier, projectIdentifier, agentIdentifier, identifier string + if attr, ok := d.GetOk("org_id"); ok { orgIdentifier = attr.(string) } @@ -431,6 +439,7 @@ func resourceGitOpsRepositoryUpdate(ctx context.Context, d *schema.ResourceData, if attr, ok := d.GetOk("identifier"); ok { identifier = attr.(string) } + updateRepoRequest := buildUpdateRepoRequest(d) resp, httpResp, err := c.RepositoriesApiService.AgentRepositoryServiceUpdateRepository(ctx, updateRepoRequest, agentIdentifier, identifier, &nextgen.RepositoriesApiAgentRepositoryServiceUpdateRepositoryOpts{ AccountIdentifier: optional.NewString(c.AccountId), diff --git a/internal/service/platform/gitops/repository_certificates/resource_gitops_repo_certs.go b/internal/service/platform/gitops/repository_certificates/resource_gitops_repo_certs.go index d75f66f1a..b1c97b301 100644 --- a/internal/service/platform/gitops/repository_certificates/resource_gitops_repo_certs.go +++ b/internal/service/platform/gitops/repository_certificates/resource_gitops_repo_certs.go @@ -187,7 +187,7 @@ func resourceGitopsRepoCertsRead(ctx context.Context, d *schema.ResourceData, me }) if err != nil { - return helpers.HandleApiError(err, d, httpResp) + return helpers.HandleReadApiError(err, d, httpResp) } // Soft delete lookup error handling diff --git a/internal/service/platform/gitops/repository_credentials/resource_gitops_repo_cred.go b/internal/service/platform/gitops/repository_credentials/resource_gitops_repo_cred.go index 15fad37d9..82b4ae4af 100644 --- a/internal/service/platform/gitops/repository_credentials/resource_gitops_repo_cred.go +++ b/internal/service/platform/gitops/repository_credentials/resource_gitops_repo_cred.go @@ -235,7 +235,7 @@ func resourceGitopsRepoCredRead(ctx context.Context, d *schema.ResourceData, met }) if err != nil { - return helpers.HandleApiError(err, d, httpResp) + return helpers.HandleReadApiError(err, d, httpResp) } // Soft delete lookup error handling