Skip to content

Commit

Permalink
fix: [CDS-99032]: Fix app project import, cluster ambigous project er…
Browse files Browse the repository at this point in the history
…ror, mapping account identifier (#1060)

Signed-off-by: Mirko Teodorovic <[email protected]>
  • Loading branch information
mteodor authored Sep 12, 2024
1 parent 086a014 commit f5f564a
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changelog/1026.txt
Original file line number Diff line number Diff line change
@@ -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
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit f5f564a

Please sign in to comment.