diff --git a/.changelog/1026.txt b/.changelog/1026.txt new file mode 100644 index 000000000..6ed0ff9ce --- /dev/null +++ b/.changelog/1026.txt @@ -0,0 +1,5 @@ +```release-note:fix +harness_platform_gitops_app_project: Fix the import +harness_platform_gitops_app_project_mapping: fix account identifier +harness_platform_gitops_cluster: fix ambigous project error +``` diff --git a/go.mod b/go.mod index 743d7db06..411e2d170 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.4 + github.com/harness/harness-go-sdk v0.4.5 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 diff --git a/go.sum b/go.sum index d1c4ccdb7..de6f6eff2 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.4 h1:ob+zPJTcMjuq+s8u5O1/SGOR+ZjqRfwGloAdKvKgd/E= -github.com/harness/harness-go-sdk v0.4.4/go.mod h1:a/1HYTgVEuNEoh3Z3IsOHZdlUNxl94KcX57ZSNVGll0= +github.com/harness/harness-go-sdk v0.4.5 h1:nXcZ5XNP+PFfRgo9A3yuQi5zTQbinWpooZq3VRBTN2E= +github.com/harness/harness-go-sdk v0.4.5/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/internal/service/platform/gitops/app_project/datasource_gitops_app_project_mapping.go b/internal/service/platform/gitops/app_project/datasource_gitops_app_project_mapping.go index 56a9330ea..8a8184f74 100644 --- a/internal/service/platform/gitops/app_project/datasource_gitops_app_project_mapping.go +++ b/internal/service/platform/gitops/app_project/datasource_gitops_app_project_mapping.go @@ -60,6 +60,7 @@ func datasourceGitopsAppProjectMappingRead(ctx context.Context, d *schema.Resour agentIdentifier := d.Get("agent_id").(string) identifier := d.Get("identifier").(string) argo_proj_name := d.Get("argo_project_name").(string) + if identifier == argo_proj_name { identifier = "" } 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 7846c2639..64134fa09 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 @@ -63,7 +63,7 @@ func ResourceGitopsAppProjectMapping() *schema.Resource { func resourceGitopsAppProjectMappingCreate(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()) - createAppProjectMappingRequest := buildCreateAppProjectMappingRequest(d) + createAppProjectMappingRequest := buildCreateAppProjectMappingRequest(c.AccountId, d) agentIdentifier := d.Get("agent_id").(string) resp, httpResp, err := c.ProjectMappingsApi.AppProjectMappingServiceCreateV2(ctx, *createAppProjectMappingRequest, agentIdentifier) @@ -100,7 +100,7 @@ func resourceGitopsAppProjectMappingRead(ctx context.Context, d *schema.Resource }) if err != nil { - return helpers.HandleApiError(err, d, httpResp) + return helpers.HandleReadApiError(err, d, httpResp) } if &resp == nil { @@ -115,7 +115,7 @@ func resourceGitopsAppProjectMappingRead(ctx context.Context, d *schema.Resource func resourceGitopsAppProjectMappingUpdate(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()) - updateAppProjectMappingRequest := buildUpdateAppProjectMappingRequest(d) + updateAppProjectMappingRequest := buildUpdateAppProjectMappingRequest(c.AccountId, d) agentIdentifier := d.Get("agent_id").(string) identifier := d.Get("identifier").(string) resp, httpResp, err := c.ProjectMappingsApi.AppProjectMappingServiceUpdateV2(ctx, *updateAppProjectMappingRequest, agentIdentifier, identifier) @@ -150,12 +150,10 @@ func resourceGitopsAppProjectMappingDelete(ctx context.Context, d *schema.Resour return nil } -func buildCreateAppProjectMappingRequest(d *schema.ResourceData) *nextgen.V1AppProjectMappingCreateRequestV2 { +func buildCreateAppProjectMappingRequest(accountId string, d *schema.ResourceData) *nextgen.V1AppProjectMappingCreateRequestV2 { var appProjectMappingRequest nextgen.V1AppProjectMappingCreateRequestV2 - if attr, ok := d.GetOk("account_id"); ok { - appProjectMappingRequest.AccountIdentifier = attr.(string) - } + appProjectMappingRequest.AccountIdentifier = accountId if attr, ok := d.GetOk("org_id"); ok { appProjectMappingRequest.OrgIdentifier = attr.(string) @@ -176,12 +174,10 @@ func buildCreateAppProjectMappingRequest(d *schema.ResourceData) *nextgen.V1AppP return &appProjectMappingRequest } -func buildUpdateAppProjectMappingRequest(d *schema.ResourceData) *nextgen.V1AppProjectMappingQueryV2 { +func buildUpdateAppProjectMappingRequest(accountId string, d *schema.ResourceData) *nextgen.V1AppProjectMappingQueryV2 { var appProjectMappingRequest nextgen.V1AppProjectMappingQueryV2 - if attr, ok := d.GetOk("account_id"); ok { - appProjectMappingRequest.AccountIdentifier = attr.(string) - } + appProjectMappingRequest.AccountIdentifier = accountId if attr, ok := d.GetOk("org_id"); ok { appProjectMappingRequest.OrgIdentifier = 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 30156ec88..ef475d04b 100644 --- a/internal/service/platform/gitops/cluster/resource_gitops_cluster.go +++ b/internal/service/platform/gitops/cluster/resource_gitops_cluster.go @@ -2,7 +2,6 @@ package cluster import ( "context" - "github.com/antihax/optional" hh "github.com/harness/harness-go-sdk/harness/helpers" "github.com/harness/harness-go-sdk/harness/nextgen" @@ -763,6 +762,10 @@ func buildClusterDetails(d *schema.ResourceData) *nextgen.ClustersCluster { } } + if requestCluster["project"] != nil { + clusterDetails.Project = requestCluster["project"].(string) + } + if requestCluster["shard"] != nil { clusterDetails.Shard = requestCluster["shard"].(string) } 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 997c29cfc..d7042f110 100644 --- a/internal/service/platform/gitops/project/resource_gitops_app_project.go +++ b/internal/service/platform/gitops/project/resource_gitops_app_project.go @@ -486,9 +486,9 @@ func resourceProjectCreate(ctx context.Context, d *schema.ResourceData, meta int c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) var orgIdentifier, projectIdentifier, agentIdentifier, accountIdentifier string var upsert bool - if attr, ok := d.GetOk("account_id"); ok { - accountIdentifier = attr.(string) - } + + accountIdentifier = c.AccountId + if attr, ok := d.GetOk("org_id"); ok { orgIdentifier = attr.(string) } @@ -529,9 +529,9 @@ func resourceProjectCreate(ctx context.Context, d *schema.ResourceData, meta int func resourceProjectRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) var orgIdentifier, projectIdentifier, agentIdentifier, query_name, accountIdentifier string - if attr, ok := d.GetOk("account_id"); ok { - accountIdentifier = attr.(string) - } + + accountIdentifier = c.AccountId + if attr, ok := d.GetOk("org_id"); ok { orgIdentifier = attr.(string) } @@ -579,6 +579,9 @@ func resourceProjectRead(ctx context.Context, d *schema.ResourceData, meta inter func resourceProjectUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) var orgIdentifier, projectIdentifier, agentIdentifier, accountIdentifier string + + accountIdentifier = c.AccountId + if attr, ok := d.GetOk("account_id"); ok { accountIdentifier = attr.(string) } @@ -617,9 +620,9 @@ func resourceProjectUpdate(ctx context.Context, d *schema.ResourceData, meta int func resourceProjectDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) var orgIdentifier, projectIdentifier, agentIdentifier, query_name, accountIdentifier string - if attr, ok := d.GetOk("account_id"); ok { - accountIdentifier = attr.(string) - } + + accountIdentifier = c.AccountId + if attr, ok := d.GetOk("org_id"); ok { orgIdentifier = attr.(string) }