@@ -484,8 +484,11 @@ func ResourceProject() *schema.Resource {
484
484
485
485
func resourceProjectCreate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
486
486
c , ctx := meta .(* internal.Session ).GetPlatformClientWithContext (ctx )
487
- var orgIdentifier , projectIdentifier , agentIdentifier string
487
+ var orgIdentifier , projectIdentifier , agentIdentifier , accountIdentifier string
488
488
var upsert bool
489
+ if attr , ok := d .GetOk ("account_id" ); ok {
490
+ accountIdentifier = attr .(string )
491
+ }
489
492
if attr , ok := d .GetOk ("org_id" ); ok {
490
493
orgIdentifier = attr .(string )
491
494
}
@@ -503,7 +506,7 @@ func resourceProjectCreate(ctx context.Context, d *schema.ResourceData, meta int
503
506
projectData := createRequestBody (d )
504
507
projectData .Upsert = upsert
505
508
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 {
507
510
OrgIdentifier : optional .NewString (orgIdentifier ),
508
511
ProjectIdentifier : optional .NewString (projectIdentifier ),
509
512
})
@@ -518,14 +521,17 @@ func resourceProjectCreate(ctx context.Context, d *schema.ResourceData, meta int
518
521
d .MarkNewResource ()
519
522
return nil
520
523
}
521
- setProjectDetails (d , & resp )
524
+ setProjectDetails (d , accountIdentifier , & resp )
522
525
523
526
return nil
524
527
}
525
528
526
529
func resourceProjectRead (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
527
530
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
+ }
529
535
if attr , ok := d .GetOk ("org_id" ); ok {
530
536
orgIdentifier = attr .(string )
531
537
}
@@ -551,29 +557,31 @@ func resourceProjectRead(ctx context.Context, d *schema.ResourceData, meta inter
551
557
}
552
558
}
553
559
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 {
555
561
OrgIdentifier : optional .NewString (orgIdentifier ),
556
562
ProjectIdentifier : optional .NewString (projectIdentifier ),
557
563
})
558
564
559
565
if err != nil {
560
- return helpers .HandleApiError (err , d , httpResp )
566
+ return helpers .HandleReadApiError (err , d , httpResp )
561
567
}
562
- // Soft delete lookup error handling
563
- // https://harness.atlassian.net/browse/PL-23765
564
- if resp .Metadata == nil {
568
+
569
+ if & resp == nil {
565
570
d .SetId ("" )
566
571
d .MarkNewResource ()
567
572
return nil
568
573
}
569
- setProjectDetails (d , & resp )
574
+ setProjectDetails (d , accountIdentifier , & resp )
570
575
571
576
return nil
572
577
}
573
578
574
579
func resourceProjectUpdate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
575
580
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
+ }
577
585
if attr , ok := d .GetOk ("org_id" ); ok {
578
586
orgIdentifier = attr .(string )
579
587
}
@@ -586,7 +594,7 @@ func resourceProjectUpdate(ctx context.Context, d *schema.ResourceData, meta int
586
594
587
595
projectData := updateRequestBody (d )
588
596
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 {
590
598
OrgIdentifier : optional .NewString (orgIdentifier ),
591
599
ProjectIdentifier : optional .NewString (projectIdentifier ),
592
600
})
@@ -601,14 +609,17 @@ func resourceProjectUpdate(ctx context.Context, d *schema.ResourceData, meta int
601
609
d .MarkNewResource ()
602
610
return nil
603
611
}
604
- setProjectDetails (d , & resp )
612
+ setProjectDetails (d , accountIdentifier , & resp )
605
613
606
614
return nil
607
615
}
608
616
609
617
func resourceProjectDelete (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
610
618
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
+ }
612
623
if attr , ok := d .GetOk ("org_id" ); ok {
613
624
orgIdentifier = attr .(string )
614
625
}
@@ -630,7 +641,7 @@ func resourceProjectDelete(ctx context.Context, d *schema.ResourceData, meta int
630
641
}
631
642
}
632
643
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 {
634
645
ProjectIdentifier : optional .NewString (projectIdentifier ),
635
646
})
636
647
@@ -1347,9 +1358,9 @@ func createRequestBody(d *schema.ResourceData) nextgen.ProjectsProjectCreateRequ
1347
1358
return projectsProjectCreateRequest
1348
1359
}
1349
1360
1350
- func setProjectDetails (d * schema.ResourceData , projects * nextgen.AppprojectsAppProject ) {
1361
+ func setProjectDetails (d * schema.ResourceData , account_id string , projects * nextgen.AppprojectsAppProject ) {
1351
1362
d .SetId (projects .Metadata .Name )
1352
- d .Set ("account_id" , "1bvyLackQK-Hapk25-Ry4w" )
1363
+ d .Set ("account_id" , account_id )
1353
1364
projectList := []interface {}{}
1354
1365
project := map [string ]interface {}{}
1355
1366
if projects .Metadata != nil {
@@ -1395,17 +1406,33 @@ func setProjectDetails(d *schema.ResourceData, projects *nextgen.AppprojectsAppP
1395
1406
spec ["source_repos" ] = sourceRepoList
1396
1407
clusterResourceWhitelist := []interface {}{}
1397
1408
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
+
1402
1420
destinationList := []interface {}{}
1403
1421
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
+
1409
1436
orphanList := []interface {}{}
1410
1437
orphan := map [string ]interface {}{}
1411
1438
orphan ["warn" ] = projects .Spec .OrphanedResources .Warn
0 commit comments