Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release and bug bash fixes #124

Merged
merged 11 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions docs/resources/api_token.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ API Token resource
## Example Usage

```terraform
resource "astro_api_token" "example_organization_token" {
resource "astro_api_token" "organization_token" {
name = "organization api token"
description = "organization api token description"
type = "ORGANIZATION"
Expand All @@ -25,7 +25,7 @@ resource "astro_api_token" "example_organization_token" {
expiry_period_in_days = 30
}

resource "astro_api_token" "example_organization_token_with_multiple_roles" {
resource "astro_api_token" "organization_token_with_multiple_roles" {
name = "organization api token with multiple roles"
description = "organization api token description"
type = "ORGANIZATION"
Expand All @@ -46,7 +46,7 @@ resource "astro_api_token" "example_organization_token_with_multiple_roles" {
}]
}

resource "astro_api_token" "example_workspace_token" {
resource "astro_api_token" "workspace_token" {
name = "workspace api token"
description = "workspace api token description"
type = "WORKSPACE"
Expand All @@ -57,7 +57,7 @@ resource "astro_api_token" "example_workspace_token" {
}]
}

resource "astro_api_token" "example_workspace_token_with_deployment_role" {
resource "astro_api_token" "workspace_token_with_deployment_role" {
name = "workspace api token"
description = "workspace api token description"
type = "WORKSPACE"
Expand All @@ -73,7 +73,7 @@ resource "astro_api_token" "example_workspace_token_with_deployment_role" {
}]
}

resource "astro_api_token" "example_deployment_token" {
resource "astro_api_token" "deployment_token" {
name = "deployment api token"
description = "deployment api token description"
type = "DEPLOYMENT"
Expand All @@ -84,7 +84,7 @@ resource "astro_api_token" "example_deployment_token" {
}]
}

resource "astro_api_token" "example_deployment_token_with_custom_role" {
resource "astro_api_token" "deployment_token_with_custom_role" {
name = "deployment api token with custom role"
description = "deployment api token description"
type = "DEPLOYMENT"
Expand All @@ -94,6 +94,22 @@ resource "astro_api_token" "example_deployment_token_with_custom_role" {
"entity_type" : "DEPLOYMENT"
}]
}

# Import an existing api token
import {
id = "clxm46ged05b301neuucdqwox" // ID of the existing api token
to = astro_api_token.imported_api_token
}
resource "astro_api_token" "imported_api_token" {
name = "imported api token"
description = "imported api token description"
type = "ORGANIZATION"
roles = [{
"role" : "ORGANIZATION_OWNER",
"entity_id" : "clx42kkcm01fo01o06agtmshg",
"entity_type" : "ORGANIZATION"
}]
}
```

<!-- schema generated by tfplugindocs -->
Expand Down
26 changes: 23 additions & 3 deletions docs/resources/team.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Team resource
## Example Usage

```terraform
resource "astro_team" "example" {
resource "astro_team" "team" {
name = "team"
description = "team-description"
description = "team description"
member_ids = ["clhpichn8002m01mqa4ocs7g6"]
organization_role = "ORGANIZATION_OWNER"
workspace_roles = [{
Expand All @@ -28,10 +28,30 @@ resource "astro_team" "example" {
}]
}

resource "astro_team" "example_with_no_optional_fields" {
resource "astro_team" "team_with_no_optional_fields" {
name = "team"
organization_role = "ORGANIZATION_OWNER"
}

# Import an existing team
import {
id = "clx486hno068301il306nuhsm" # ID of the existing team
to = astro_team.imported_team
}
resource "astro_team" "imported_team" {
name = "imported team"
description = "imported team description"
member_ids = ["clhpichn8002m01mqa4ocs7g6"]
organization_role = "ORGANIZATION_OWNER"
workspace_roles = [{
workspace_id = "clx42sxw501gl01o0gjenthnh"
role = "WORKSPACE_OWNER"
}]
deployment_roles = [{
deployment_id = "clyn6kxud003x01mtxmccegnh"
role = "DEPLOYMENT_ADMIN"
}]
}
```

<!-- schema generated by tfplugindocs -->
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/user_invite.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ User Invite resource
## Example Usage

```terraform
resource "astro_user_invite" "example" {
resource "astro_user_invite" "user_invite" {
email = "email@organization.com"
role = "ORGANIZATION_MEMBER"
}
Expand Down
26 changes: 26 additions & 0 deletions docs/resources/user_roles.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,32 @@ resource "astro_user_roles" "all_roles" {
}
]
}

# Import an existing user roles
import {
id = "clzaftcaz006001lhkey6qzzg" # ID of the existing user
to = astro_user_roles.imported_user_roles
}
resource "astro_user_roles" "imported_user_roles" {
user_id = "clzaftcaz006001lhkey6qzzg"
organization_role = "ORGANIZATION_MEMBER"
workspace_roles = [
{
workspace_id = "clx42sxw501gl01o0gjenthnh"
role = "WORKSPACE_OWNER"
},
{
workspace_id = "clzafte7z006001lhkey6qzzb"
role = "WORKSPACE_MEMBER"
}
]
deployment_roles = [
{
deployment_id = "clyn6kxud003x01mtxmccegnh"
role = "my custom role"
}
]
}
```

<!-- schema generated by tfplugindocs -->
Expand Down
28 changes: 22 additions & 6 deletions examples/resources/astro_api_token/resource.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "astro_api_token" "example_organization_token" {
resource "astro_api_token" "organization_token" {
name = "organization api token"
description = "organization api token description"
type = "ORGANIZATION"
Expand All @@ -10,7 +10,7 @@ resource "astro_api_token" "example_organization_token" {
expiry_period_in_days = 30
}

resource "astro_api_token" "example_organization_token_with_multiple_roles" {
resource "astro_api_token" "organization_token_with_multiple_roles" {
name = "organization api token with multiple roles"
description = "organization api token description"
type = "ORGANIZATION"
Expand All @@ -31,7 +31,7 @@ resource "astro_api_token" "example_organization_token_with_multiple_roles" {
}]
}

resource "astro_api_token" "example_workspace_token" {
resource "astro_api_token" "workspace_token" {
name = "workspace api token"
description = "workspace api token description"
type = "WORKSPACE"
Expand All @@ -42,7 +42,7 @@ resource "astro_api_token" "example_workspace_token" {
}]
}

resource "astro_api_token" "example_workspace_token_with_deployment_role" {
resource "astro_api_token" "workspace_token_with_deployment_role" {
name = "workspace api token"
description = "workspace api token description"
type = "WORKSPACE"
Expand All @@ -58,7 +58,7 @@ resource "astro_api_token" "example_workspace_token_with_deployment_role" {
}]
}

resource "astro_api_token" "example_deployment_token" {
resource "astro_api_token" "deployment_token" {
name = "deployment api token"
description = "deployment api token description"
type = "DEPLOYMENT"
Expand All @@ -69,7 +69,7 @@ resource "astro_api_token" "example_deployment_token" {
}]
}

resource "astro_api_token" "example_deployment_token_with_custom_role" {
resource "astro_api_token" "deployment_token_with_custom_role" {
name = "deployment api token with custom role"
description = "deployment api token description"
type = "DEPLOYMENT"
Expand All @@ -79,3 +79,19 @@ resource "astro_api_token" "example_deployment_token_with_custom_role" {
"entity_type" : "DEPLOYMENT"
}]
}

# Import an existing api token
import {
id = "clxm46ged05b301neuucdqwox" // ID of the existing api token
to = astro_api_token.imported_api_token
}
resource "astro_api_token" "imported_api_token" {
name = "imported api token"
description = "imported api token description"
type = "ORGANIZATION"
roles = [{
"role" : "ORGANIZATION_OWNER",
"entity_id" : "clx42kkcm01fo01o06agtmshg",
"entity_type" : "ORGANIZATION"
}]
}
25 changes: 22 additions & 3 deletions examples/resources/astro_team/resource.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "astro_team" "example" {
resource "astro_team" "team" {
name = "team"
description = "team-description"
description = "team description"
member_ids = ["clhpichn8002m01mqa4ocs7g6"]
organization_role = "ORGANIZATION_OWNER"
workspace_roles = [{
Expand All @@ -13,8 +13,27 @@ resource "astro_team" "example" {
}]
}

resource "astro_team" "example_with_no_optional_fields" {
resource "astro_team" "team_with_no_optional_fields" {
name = "team"
organization_role = "ORGANIZATION_OWNER"
}

# Import an existing team
import {
id = "clx486hno068301il306nuhsm" # ID of the existing team
to = astro_team.imported_team
}
resource "astro_team" "imported_team" {
name = "imported team"
description = "imported team description"
member_ids = ["clhpichn8002m01mqa4ocs7g6"]
organization_role = "ORGANIZATION_OWNER"
workspace_roles = [{
workspace_id = "clx42sxw501gl01o0gjenthnh"
role = "WORKSPACE_OWNER"
}]
deployment_roles = [{
deployment_id = "clyn6kxud003x01mtxmccegnh"
role = "DEPLOYMENT_ADMIN"
}]
}
2 changes: 1 addition & 1 deletion examples/resources/astro_user_invite/resource.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "astro_user_invite" "example" {
resource "astro_user_invite" "user_invite" {
email = "email@organization.com"
role = "ORGANIZATION_MEMBER"
}
26 changes: 26 additions & 0 deletions examples/resources/astro_user_roles/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,30 @@ resource "astro_user_roles" "all_roles" {
role = "my custom role"
}
]
}

# Import an existing user roles
import {
id = "clzaftcaz006001lhkey6qzzg" # ID of the existing user
to = astro_user_roles.imported_user_roles
}
resource "astro_user_roles" "imported_user_roles" {
user_id = "clzaftcaz006001lhkey6qzzg"
organization_role = "ORGANIZATION_MEMBER"
workspace_roles = [
{
workspace_id = "clx42sxw501gl01o0gjenthnh"
role = "WORKSPACE_OWNER"
},
{
workspace_id = "clzafte7z006001lhkey6qzzb"
role = "WORKSPACE_MEMBER"
}
]
deployment_roles = [
{
deployment_id = "clyn6kxud003x01mtxmccegnh"
role = "my custom role"
}
]
}
8 changes: 4 additions & 4 deletions internal/provider/common/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ func ValidateWorkspaceDeploymentRoles(ctx context.Context, input ValidateWorkspa
DeploymentIds: &deploymentIds,
})
if err != nil {
tflog.Error(ctx, "failed to mutate Team roles", map[string]interface{}{"error": err})
tflog.Error(ctx, "failed to mutate roles", map[string]interface{}{"error": err})
return diag.Diagnostics{diag.NewErrorDiagnostic(
"Client Error",
fmt.Sprintf("Unable to mutate Team roles and list deployments, got error: %s", err),
fmt.Sprintf("Unable to mutate roles and list deployments, got error: %s", err),
),
}
}
Expand All @@ -129,9 +129,9 @@ func ValidateWorkspaceDeploymentRoles(ctx context.Context, input ValidateWorkspa
// check if deploymentWorkspaceIds are in workspaceIds
workspaceIds = lo.Intersect(lo.Uniq(workspaceIds), lo.Uniq(deploymentWorkspaceIds))
if len(workspaceIds) != len(deploymentWorkspaceIds) {
tflog.Error(ctx, "failed to mutate Team roles", map[string]interface{}{"error": err})
tflog.Error(ctx, "failed to mutate roles")
return diag.Diagnostics{diag.NewErrorDiagnostic(
"Unable to mutate Team roles, not every deployment role has a corresponding workspace role",
"Unable to mutate roles, not every deployment role has a corresponding workspace role",
"Please ensure that every deployment role has a corresponding workspace role",
),
}
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/models/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (data *TeamDataSource) ReadFromResponse(ctx context.Context, team *iam.Team
if team.RolesCount != nil {
data.RolesCount = types.Int64Value(int64(*team.RolesCount))
} else {
data.RolesCount = types.Int64Value(0)
data.RolesCount = types.Int64Value(1)
}

data.CreatedAt = types.StringValue(team.CreatedAt.String())
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/models/user_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (data *UserRoles) ReadFromResponse(
) diag.Diagnostics {
var diags diag.Diagnostics
data.UserId = types.StringValue(userId)
data.OrganizationRole = types.StringPointerValue((*string)(userRoles.OrganizationRole))
data.OrganizationRole = types.StringValue(string(*userRoles.OrganizationRole))
data.WorkspaceRoles, diags = utils.ObjectSet(ctx, userRoles.WorkspaceRoles, schemas.WorkspaceRoleAttributeTypes(), WorkspaceRoleTypesObject)
if diags.HasError() {
return diags
Expand Down
Loading