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

CDPCP-10932 - GCP environment creation Terraform Resource fails due to unknown values on some parameters #69

Merged
merged 1 commit into from
Nov 29, 2023
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
15 changes: 9 additions & 6 deletions resources/environments/converter_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package environments

import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
Expand All @@ -21,7 +22,7 @@ import (
)

func toGcpEnvironmentRequest(ctx context.Context, model *gcpEnvironmentResourceModel) *environmentsmodels.CreateGCPEnvironmentRequest {
res := &environmentsmodels.CreateGCPEnvironmentRequest{
req := &environmentsmodels.CreateGCPEnvironmentRequest{
CredentialName: model.CredentialName.ValueStringPointer(),
Description: model.Description.ValueString(),
EnableTunnel: model.EnableTunnel.ValueBool(),
Expand All @@ -41,28 +42,30 @@ func toGcpEnvironmentRequest(ctx context.Context, model *gcpEnvironmentResourceM
WorkloadAnalytics: model.WorkloadAnalytics.ValueBool(),
}
if model.FreeIpa != nil {
res.FreeIpa = &environmentsmodels.GCPFreeIpaCreationRequest{
tflog.Debug(ctx, fmt.Sprintf("model.FreeIpa: %+v\n", model.FreeIpa))
req.FreeIpa = &environmentsmodels.GCPFreeIpaCreationRequest{
InstanceCountByGroup: int32(model.FreeIpa.InstanceCountByGroup.ValueInt64()),
InstanceType: model.FreeIpa.InstanceType.ValueString(),
Recipes: utils.FromSetValueToStringList(model.FreeIpa.Recipes),
}
tflog.Debug(ctx, fmt.Sprintf("req.FreeIpa: %+v\n", req.FreeIpa))
}

if model.LogStorage != nil {
res.LogStorage = &environmentsmodels.GcpLogStorageRequest{
req.LogStorage = &environmentsmodels.GcpLogStorageRequest{
StorageLocationBase: model.LogStorage.StorageLocationBase.ValueStringPointer(),
BackupStorageLocationBase: model.LogStorage.BackupStorageLocationBase.ValueString(),
ServiceAccountEmail: model.LogStorage.ServiceAccountEmail.ValueStringPointer(),
}
}
if model.SecurityAccess != nil {
res.SecurityAccess = &environmentsmodels.GcpSecurityAccessRequest{
req.SecurityAccess = &environmentsmodels.GcpSecurityAccessRequest{
DefaultSecurityGroupID: model.SecurityAccess.DefaultSecurityGroupId.ValueString(),
SecurityGroupIDForKnox: model.SecurityAccess.SecurityGroupIdForKnox.ValueString(),
}
}
res.Tags = ConvertGcpTags(ctx, model.Tags)
return res
req.Tags = ConvertGcpTags(ctx, model.Tags)
return req
}

func toGcpEnvironmentResource(ctx context.Context, env *environmentsmodels.Environment, model *gcpEnvironmentResourceModel, pollingOptions *utils.PollingOptions, diags *diag.Diagnostics) {
Expand Down
8 changes: 1 addition & 7 deletions resources/environments/schema_gcp_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ package environments
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"

"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/mapplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
Expand Down Expand Up @@ -176,15 +175,10 @@ func (r *gcpEnvironmentResource) Schema(_ context.Context, _ resource.SchemaRequ
"instance_type": schema.StringAttribute{
MarkdownDescription: "Custom instance type of FreeIPA instances.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"recipes": schema.SetAttribute{
MarkdownDescription: "The recipes for the FreeIPA cluster.",
Optional: true,
Computed: true,
ElementType: types.StringType,
},
},
Expand Down
Loading