Skip to content

Commit f484188

Browse files
authored
fix: [CDS-99032]: Removed the accountIdentifier (#1056)
* fix: [CDS-99032]: Removed the accountIdentifer * fix: [CDS-99032]: fix the accountIdentifer * fix: [CDS-99032]: fix the accountIdentifer * fix: [CDS-99032]: fix the accountIdentifer * fix: [CDS-99032]: fix the accountIdentifer * fix: [CDS-99032]: fix the accountIdentifer * fix: [CDS-99032]: fix the accountIdentifer
1 parent 1512f79 commit f484188

File tree

3 files changed

+63
-30
lines changed

3 files changed

+63
-30
lines changed

.changelog/1025.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:fix
2+
harness_platform_gitops_app_project: Fix the accountIdentifier context
3+
```

internal/service/platform/gitops/project/data_source_gitops_app_project.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ func DataSourceGitOpsProject() *schema.Resource {
4747

4848
func dataSourceProjectRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
4949
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
50-
var orgIdentifier, projectIdentifier, agentIdentifier, query_name string
50+
var orgIdentifier, projectIdentifier, agentIdentifier, query_name, accountIdentifier string
51+
if attr, ok := d.GetOk("account_id"); ok {
52+
accountIdentifier = attr.(string)
53+
}
5154
if attr, ok := d.GetOk("org_id"); ok {
5255
orgIdentifier = attr.(string)
5356
}
@@ -62,13 +65,13 @@ func dataSourceProjectRead(ctx context.Context, d *schema.ResourceData, meta int
6265
query_name = attr.(string)
6366
}
6467

65-
resp, httpResp, err := c.ProjectGitOpsApi.AgentProjectServiceGet(ctx, agentIdentifier, query_name, c.AccountId, &nextgen.ProjectsApiAgentProjectServiceGetOpts{
68+
resp, httpResp, err := c.ProjectGitOpsApi.AgentProjectServiceGet(ctx, agentIdentifier, query_name, accountIdentifier, &nextgen.ProjectsApiAgentProjectServiceGetOpts{
6669
OrgIdentifier: optional.NewString(orgIdentifier),
6770
ProjectIdentifier: optional.NewString(projectIdentifier),
6871
})
6972

7073
if err != nil {
71-
return helpers.HandleApiError(err, d, httpResp)
74+
return helpers.HandleReadApiError(err, d, httpResp)
7275
}
7376
// Soft delete lookup error handling
7477
// https://harness.atlassian.net/browse/PL-23765
@@ -77,7 +80,7 @@ func dataSourceProjectRead(ctx context.Context, d *schema.ResourceData, meta int
7780
d.MarkNewResource()
7881
return nil
7982
}
80-
setProjectDetails(d, &resp)
83+
setProjectDetails(d, accountIdentifier, &resp)
8184

8285
return nil
8386
}

internal/service/platform/gitops/project/resource_gitops_app_project.go

+53-26
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,11 @@ func ResourceProject() *schema.Resource {
484484

485485
func resourceProjectCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
486486
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
487-
var orgIdentifier, projectIdentifier, agentIdentifier string
487+
var orgIdentifier, projectIdentifier, agentIdentifier, accountIdentifier string
488488
var upsert bool
489+
if attr, ok := d.GetOk("account_id"); ok {
490+
accountIdentifier = attr.(string)
491+
}
489492
if attr, ok := d.GetOk("org_id"); ok {
490493
orgIdentifier = attr.(string)
491494
}
@@ -503,7 +506,7 @@ func resourceProjectCreate(ctx context.Context, d *schema.ResourceData, meta int
503506
projectData := createRequestBody(d)
504507
projectData.Upsert = upsert
505508

506-
resp, httpResp, err := c.ProjectGitOpsApi.AgentProjectServiceCreate(ctx, projectData, c.AccountId, agentIdentifier, &nextgen.ProjectsApiAgentProjectServiceCreateOpts{
509+
resp, httpResp, err := c.ProjectGitOpsApi.AgentProjectServiceCreate(ctx, projectData, accountIdentifier, agentIdentifier, &nextgen.ProjectsApiAgentProjectServiceCreateOpts{
507510
OrgIdentifier: optional.NewString(orgIdentifier),
508511
ProjectIdentifier: optional.NewString(projectIdentifier),
509512
})
@@ -518,14 +521,17 @@ func resourceProjectCreate(ctx context.Context, d *schema.ResourceData, meta int
518521
d.MarkNewResource()
519522
return nil
520523
}
521-
setProjectDetails(d, &resp)
524+
setProjectDetails(d, accountIdentifier, &resp)
522525

523526
return nil
524527
}
525528

526529
func resourceProjectRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
527530
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
528-
var orgIdentifier, projectIdentifier, agentIdentifier, query_name string
531+
var orgIdentifier, projectIdentifier, agentIdentifier, query_name, accountIdentifier string
532+
if attr, ok := d.GetOk("account_id"); ok {
533+
accountIdentifier = attr.(string)
534+
}
529535
if attr, ok := d.GetOk("org_id"); ok {
530536
orgIdentifier = attr.(string)
531537
}
@@ -551,29 +557,31 @@ func resourceProjectRead(ctx context.Context, d *schema.ResourceData, meta inter
551557
}
552558
}
553559

554-
resp, httpResp, err := c.ProjectGitOpsApi.AgentProjectServiceGet(ctx, agentIdentifier, query_name, c.AccountId, &nextgen.ProjectsApiAgentProjectServiceGetOpts{
560+
resp, httpResp, err := c.ProjectGitOpsApi.AgentProjectServiceGet(ctx, agentIdentifier, query_name, accountIdentifier, &nextgen.ProjectsApiAgentProjectServiceGetOpts{
555561
OrgIdentifier: optional.NewString(orgIdentifier),
556562
ProjectIdentifier: optional.NewString(projectIdentifier),
557563
})
558564

559565
if err != nil {
560-
return helpers.HandleApiError(err, d, httpResp)
566+
return helpers.HandleReadApiError(err, d, httpResp)
561567
}
562-
// Soft delete lookup error handling
563-
// https://harness.atlassian.net/browse/PL-23765
564-
if resp.Metadata == nil {
568+
569+
if &resp == nil {
565570
d.SetId("")
566571
d.MarkNewResource()
567572
return nil
568573
}
569-
setProjectDetails(d, &resp)
574+
setProjectDetails(d, accountIdentifier, &resp)
570575

571576
return nil
572577
}
573578

574579
func resourceProjectUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
575580
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
576-
var orgIdentifier, projectIdentifier, agentIdentifier string
581+
var orgIdentifier, projectIdentifier, agentIdentifier, accountIdentifier string
582+
if attr, ok := d.GetOk("account_id"); ok {
583+
accountIdentifier = attr.(string)
584+
}
577585
if attr, ok := d.GetOk("org_id"); ok {
578586
orgIdentifier = attr.(string)
579587
}
@@ -586,7 +594,7 @@ func resourceProjectUpdate(ctx context.Context, d *schema.ResourceData, meta int
586594

587595
projectData := updateRequestBody(d)
588596

589-
resp, httpResp, err := c.ProjectGitOpsApi.AgentProjectServiceUpdate(ctx, projectData, c.AccountId, agentIdentifier, projectData.Project.Metadata.Name, &nextgen.ProjectsApiAgentProjectServiceUpdateOpts{
597+
resp, httpResp, err := c.ProjectGitOpsApi.AgentProjectServiceUpdate(ctx, projectData, accountIdentifier, agentIdentifier, projectData.Project.Metadata.Name, &nextgen.ProjectsApiAgentProjectServiceUpdateOpts{
590598
OrgIdentifier: optional.NewString(orgIdentifier),
591599
ProjectIdentifier: optional.NewString(projectIdentifier),
592600
})
@@ -601,14 +609,17 @@ func resourceProjectUpdate(ctx context.Context, d *schema.ResourceData, meta int
601609
d.MarkNewResource()
602610
return nil
603611
}
604-
setProjectDetails(d, &resp)
612+
setProjectDetails(d, accountIdentifier, &resp)
605613

606614
return nil
607615
}
608616

609617
func resourceProjectDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
610618
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
611-
var orgIdentifier, projectIdentifier, agentIdentifier, query_name string
619+
var orgIdentifier, projectIdentifier, agentIdentifier, query_name, accountIdentifier string
620+
if attr, ok := d.GetOk("account_id"); ok {
621+
accountIdentifier = attr.(string)
622+
}
612623
if attr, ok := d.GetOk("org_id"); ok {
613624
orgIdentifier = attr.(string)
614625
}
@@ -630,7 +641,7 @@ func resourceProjectDelete(ctx context.Context, d *schema.ResourceData, meta int
630641
}
631642
}
632643

633-
_, httpResp, err := c.ProjectGitOpsApi.AgentProjectServiceDelete(ctx, agentIdentifier, query_name, c.AccountId, orgIdentifier, &nextgen.ProjectsApiAgentProjectServiceDeleteOpts{
644+
_, httpResp, err := c.ProjectGitOpsApi.AgentProjectServiceDelete(ctx, agentIdentifier, query_name, accountIdentifier, orgIdentifier, &nextgen.ProjectsApiAgentProjectServiceDeleteOpts{
634645
ProjectIdentifier: optional.NewString(projectIdentifier),
635646
})
636647

@@ -1347,9 +1358,9 @@ func createRequestBody(d *schema.ResourceData) nextgen.ProjectsProjectCreateRequ
13471358
return projectsProjectCreateRequest
13481359
}
13491360

1350-
func setProjectDetails(d *schema.ResourceData, projects *nextgen.AppprojectsAppProject) {
1361+
func setProjectDetails(d *schema.ResourceData, account_id string, projects *nextgen.AppprojectsAppProject) {
13511362
d.SetId(projects.Metadata.Name)
1352-
d.Set("account_id", "1bvyLackQK-Hapk25-Ry4w")
1363+
d.Set("account_id", account_id)
13531364
projectList := []interface{}{}
13541365
project := map[string]interface{}{}
13551366
if projects.Metadata != nil {
@@ -1395,17 +1406,33 @@ func setProjectDetails(d *schema.ResourceData, projects *nextgen.AppprojectsAppP
13951406
spec["source_repos"] = sourceRepoList
13961407
clusterResourceWhitelist := []interface{}{}
13971408
clusterResourceWhite := map[string]interface{}{}
1398-
clusterResourceWhite["group"] = projects.Spec.ClusterResourceWhitelist[0].Group
1399-
clusterResourceWhite["kind"] = projects.Spec.ClusterResourceWhitelist[0].Kind
1400-
clusterResourceWhitelist = append(clusterResourceWhitelist, clusterResourceWhite)
1401-
spec["cluster_resource_whitelist"] = clusterResourceWhitelist
1409+
if len(projects.Spec.ClusterResourceWhitelist) > 0 {
1410+
clusterResourceWhite["group"] = projects.Spec.ClusterResourceWhitelist[0].Group
1411+
clusterResourceWhite["kind"] = projects.Spec.ClusterResourceWhitelist[0].Kind
1412+
}
1413+
if len(clusterResourceWhite) > 0 {
1414+
clusterResourceWhitelist = append(clusterResourceWhitelist, clusterResourceWhite)
1415+
}
1416+
if len(clusterResourceWhitelist) > 0 {
1417+
spec["cluster_resource_whitelist"] = clusterResourceWhitelist
1418+
}
1419+
14021420
destinationList := []interface{}{}
14031421
destination := map[string]interface{}{}
1404-
destination["namespace"] = projects.Spec.Destinations[0].Namespace
1405-
destination["server"] = projects.Spec.Destinations[0].Server
1406-
destination["name"] = projects.Spec.Destinations[0].Name
1407-
destinationList = append(destinationList, destination)
1408-
spec["destinations"] = destinationList
1422+
if len(projects.Spec.Destinations) > 0 {
1423+
destination["namespace"] = projects.Spec.Destinations[0].Namespace
1424+
destination["server"] = projects.Spec.Destinations[0].Server
1425+
destination["name"] = projects.Spec.Destinations[0].Name
1426+
}
1427+
1428+
if len(destination) > 0 {
1429+
destinationList = append(destinationList, destination)
1430+
}
1431+
1432+
if len(destinationList) > 0 {
1433+
spec["destinations"] = destinationList
1434+
}
1435+
14091436
orphanList := []interface{}{}
14101437
orphan := map[string]interface{}{}
14111438
orphan["warn"] = projects.Spec.OrphanedResources.Warn

0 commit comments

Comments
 (0)