generated from hashicorp/terraform-provider-scaffolding-framework
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Hybrid Cluster Workspace Authorization Resource (#77)
Co-authored-by: Vandy Liu <[email protected]>
- Loading branch information
Showing
12 changed files
with
635 additions
and
48 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
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,31 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "astro_hybrid_cluster_workspace_authorization Resource - astro" | ||
subcategory: "" | ||
description: |- | ||
Hybrid cluster workspace authorization resource | ||
--- | ||
|
||
# astro_hybrid_cluster_workspace_authorization (Resource) | ||
|
||
Hybrid cluster workspace authorization resource | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "astro_hybrid_cluster_workspace_authorization" "example" { | ||
cluster_id = "clk8h0fv1006801j8yysfybbt" | ||
workspace_ids = ["cl70oe7cu445571iynrkthtybl", "cl70oe7cu445571iynrkthacsd"] | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `cluster_id` (String) The ID of the hybrid cluster to set authorizations for | ||
|
||
### Optional | ||
|
||
- `workspace_ids` (Set of String) The IDs of the workspaces to authorize for the hybrid cluster |
4 changes: 4 additions & 0 deletions
4
examples/resources/astro_hybrid_cluster_workspace_authorization/resource.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,4 @@ | ||
resource "astro_hybrid_cluster_workspace_authorization" "example" { | ||
cluster_id = "clk8h0fv1006801j8yysfybbt" | ||
workspace_ids = ["cl70oe7cu445571iynrkthtybl", "cl70oe7cu445571iynrkthacsd"] | ||
} |
30 changes: 30 additions & 0 deletions
30
internal/provider/models/hybrid_cluster_workspace_authorization.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,30 @@ | ||
package models | ||
|
||
import ( | ||
"github.com/astronomer/terraform-provider-astro/internal/clients/platform" | ||
"github.com/astronomer/terraform-provider-astro/internal/utils" | ||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
type HybridClusterWorkspaceAuthorizationResource struct { | ||
ClusterId types.String `tfsdk:"cluster_id"` | ||
WorkspaceIds types.Set `tfsdk:"workspace_ids"` | ||
} | ||
|
||
func (data *HybridClusterWorkspaceAuthorizationResource) ReadFromResponse( | ||
cluster *platform.Cluster, | ||
) diag.Diagnostics { | ||
var diags diag.Diagnostics | ||
data.ClusterId = types.StringValue(cluster.Id) | ||
if cluster.WorkspaceIds == nil || len(*cluster.WorkspaceIds) == 0 { | ||
data.WorkspaceIds = types.SetNull(types.StringType) | ||
} else { | ||
data.WorkspaceIds, diags = utils.StringSet(cluster.WorkspaceIds) | ||
if diags.HasError() { | ||
return diags | ||
} | ||
} | ||
|
||
return nil | ||
} |
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
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
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,47 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/astronomer/terraform-provider-astro/internal/clients" | ||
"github.com/astronomer/terraform-provider-astro/internal/clients/platform" | ||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" | ||
) | ||
|
||
// ClusterResourceRefreshFunc returns a retry.StateRefreshFunc that polls the platform API for the cluster status | ||
// If the cluster is not found, it returns "DELETED" status | ||
// If the cluster is found, it returns the cluster status | ||
// If there is an error, it returns the error | ||
// WaitForStateContext will keep polling until the target status is reached, the timeout is reached or an err is returned | ||
func ClusterResourceRefreshFunc(ctx context.Context, platformClient *platform.ClientWithResponses, organizationId string, clusterId string) retry.StateRefreshFunc { | ||
return func() (any, string, error) { | ||
cluster, err := platformClient.GetClusterWithResponse(ctx, organizationId, clusterId) | ||
if err != nil { | ||
tflog.Error(ctx, "failed to get cluster while polling for cluster 'CREATED' status", map[string]interface{}{"error": err}) | ||
return nil, "", err | ||
} | ||
statusCode, diagnostic := clients.NormalizeAPIError(ctx, cluster.HTTPResponse, cluster.Body) | ||
if statusCode == http.StatusNotFound { | ||
return &platform.Cluster{}, "DELETED", nil | ||
} | ||
if diagnostic != nil { | ||
return nil, "", fmt.Errorf("error getting cluster %s", diagnostic.Detail()) | ||
} | ||
if cluster != nil && cluster.JSON200 != nil { | ||
switch cluster.JSON200.Status { | ||
case platform.ClusterStatusCREATED: | ||
return cluster.JSON200, string(cluster.JSON200.Status), nil | ||
case platform.ClusterStatusUPDATEFAILED, platform.ClusterStatusCREATEFAILED: | ||
return cluster.JSON200, string(cluster.JSON200.Status), fmt.Errorf("cluster mutation failed for cluster '%v'", cluster.JSON200.Id) | ||
case platform.ClusterStatusCREATING, platform.ClusterStatusUPDATING: | ||
return cluster.JSON200, string(cluster.JSON200.Status), nil | ||
default: | ||
return cluster.JSON200, string(cluster.JSON200.Status), fmt.Errorf("unexpected cluster status '%v' for cluster '%v'", cluster.JSON200.Status, cluster.JSON200.Id) | ||
} | ||
} | ||
return nil, "", fmt.Errorf("error getting cluster %s", clusterId) | ||
} | ||
} |
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
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
Oops, something went wrong.