generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CCM-19455]: Added Support for Cluster Orchestrator Resource (#1084)
* [CCM-19455]: Added Support for Cluster Orchestrator * updated doc * added subcategory in doc * Updated the go sdk * removed import.sh file, import will be supported in a subsequent version * added changelog
- Loading branch information
Showing
10 changed files
with
282 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-resource | ||
harness_cluster_orchestrator - Added Cluster Orchestrator resource in Harness terraform provider | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "harness_cluster_orchestrator Data Source - terraform-provider-harness" | ||
subcategory: "Next Gen" | ||
description: |- | ||
Data source for retrieving a Harness ClusterOrchestrator. | ||
--- | ||
|
||
# harness_cluster_orchestrator (Data Source) | ||
|
||
Data source for retrieving a Harness ClusterOrchestrator. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "harness_cluster_orchestrator" "example" { | ||
identifier = "identifier" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `cluster_endpoint` (String) Endpoint of the k8s cluster being onboarded under the orchestrator | ||
- `k8s_connector_id` (String) ID of the Harness Kubernetes Connector Being used | ||
- `name` (String) Name of the Orchestrator | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "harness_cluster_orchestrator Resource - terraform-provider-harness" | ||
subcategory: "Next Gen" | ||
description: |- | ||
Resource for creating ClusterOrchestrators. | ||
--- | ||
|
||
# harness_cluster_orchestrator (Resource) | ||
|
||
Resource for creating ClusterOrchestrators. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "harness_cluster_orchestrator" "test" { | ||
name = "name" | ||
cluster_endpoint = "http://test.test.com" | ||
k8s_connector_id = "test" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `cluster_endpoint` (String) Endpoint of the k8s cluster being onboarded under the orchestrator | ||
- `k8s_connector_id` (String) ID of the Harness Kubernetes Connector Being used | ||
- `name` (String) Name of the Orchestrator | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
# Import using the Harness aws cloud provider id. | ||
terraform import harness_cluster_orchestrator.example <provider_id> | ||
``` |
3 changes: 3 additions & 0 deletions
3
examples/data-sources/harness_cluster_orchestrator/data-source.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
data "harness_cluster_orchestrator" "example" { | ||
identifier = "identifier" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
resource "harness_cluster_orchestrator" "test" { | ||
name = "name" | ||
cluster_endpoint = "http://test.test.com" | ||
k8s_connector_id = "test" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
internal/service/platform/cluster_orchestrator/clusterorch_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package cluster_orchestrator | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/harness/terraform-provider-harness/helpers" | ||
"github.com/harness/terraform-provider-harness/internal" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func DataSourceClusterOrchestrator() *schema.Resource { | ||
resource := &schema.Resource{ | ||
Description: "Data source for retrieving a Harness ClusterOrchestrator.", | ||
|
||
ReadContext: resourceClusterOrchestratorRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Description: "Name of the Orchestrator", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"cluster_endpoint": { | ||
Description: "Endpoint of the k8s cluster being onboarded under the orchestrator", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"k8s_connector_id": { | ||
Description: "ID of the Harness Kubernetes Connector Being used", | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
}, | ||
} | ||
|
||
return resource | ||
} | ||
|
||
func resourceClusterOrchestratorRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) | ||
|
||
Identifier := d.Id() | ||
|
||
resp, httpResp, err := c.CloudCostClusterOrchestratorApi.ClusterOrchestratorDetails(ctx, c.AccountId, Identifier) | ||
|
||
if err != nil { | ||
return helpers.HandleReadApiError(err, d, httpResp) | ||
} | ||
|
||
if resp.Response != nil { | ||
setId(d, resp.Response.ID) | ||
} | ||
|
||
return nil | ||
} |
67 changes: 67 additions & 0 deletions
67
internal/service/platform/cluster_orchestrator/clusterorch_resource.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package cluster_orchestrator | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/harness/harness-go-sdk/harness/nextgen" | ||
"github.com/harness/terraform-provider-harness/helpers" | ||
"github.com/harness/terraform-provider-harness/internal" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func ResourceClusterOrchestrator() *schema.Resource { | ||
resource := &schema.Resource{ | ||
Description: "Resource for creating ClusterOrchestrators.", | ||
|
||
CreateContext: resourceClusterOrchestratorCreate, | ||
UpdateContext: resourceClusterOrchestratorCreate, | ||
ReadContext: resourceClusterOrchestratorCreate, | ||
DeleteContext: resourceClusterOrchestratorDelete, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Description: "Name of the Orchestrator", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"cluster_endpoint": { | ||
Description: "Endpoint of the k8s cluster being onboarded under the orchestrator", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"k8s_connector_id": { | ||
Description: "ID of the Harness Kubernetes Connector Being used", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
}, | ||
} | ||
|
||
return resource | ||
} | ||
|
||
func resourceClusterOrchestratorCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) | ||
body := buildClusterOrch(d) | ||
var err error | ||
var resp nextgen.ClusterOrchestratorResponse | ||
var httpResp *http.Response | ||
|
||
resp, httpResp, err = c.CloudCostClusterOrchestratorApi.CreateClusterOrchestrator(ctx, c.AccountId, body) | ||
|
||
if err != nil { | ||
return helpers.HandleApiError(err, d, httpResp) | ||
} | ||
|
||
if resp.Response != nil { | ||
setId(d, resp.Response.ID) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceClusterOrchestratorDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
return nil | ||
} |
38 changes: 38 additions & 0 deletions
38
internal/service/platform/cluster_orchestrator/clusterorch_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cluster_orchestrator_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/harness/terraform-provider-harness/internal/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestResourceClusterOrchestrator(t *testing.T) { | ||
name := "terraform-clusterorch-test" | ||
resourceName := "harness_cluster_orchestrator.test" | ||
|
||
resource.UnitTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.TestAccPreCheck(t) }, | ||
ProviderFactories: acctest.ProviderFactories, | ||
// CheckDestroy: testRuleDestroy(resourceName), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testClusterOrch(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(resourceName, "name", name), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testClusterOrch(name string) string { | ||
return fmt.Sprintf(` | ||
resource "harness_cluster_orchestrator" "test" { | ||
name = "%s" | ||
cluster_endpoint = "http://test.com" | ||
k8s_connector_id = "TestDoNotDelete" | ||
} | ||
`, name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package cluster_orchestrator | ||
|
||
import ( | ||
"github.com/harness/harness-go-sdk/harness/nextgen" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func buildClusterOrch(d *schema.ResourceData) nextgen.CreateClusterOrchestratorDto { | ||
|
||
clusterOrch := &nextgen.CreateClusterOrchestratorDto{} | ||
|
||
if attr, ok := d.GetOk("name"); ok { | ||
clusterOrch.Name = attr.(string) | ||
} | ||
if attr, ok := d.GetOk("k8s_connector_id"); ok { | ||
clusterOrch.K8sConnID = attr.(string) | ||
} | ||
userCfg := nextgen.ClusterOrchestratorUserConfig{} | ||
|
||
if attr, ok := d.GetOk("cluster_endpoint"); ok { | ||
userCfg.ClusterEndPoint = attr.(string) | ||
} | ||
clusterOrch.UserConfig = userCfg | ||
|
||
return *clusterOrch | ||
|
||
} | ||
|
||
func setId(d *schema.ResourceData, id string) { | ||
d.SetId(id) | ||
d.Set("identifier", id) | ||
} |