Skip to content

Commit

Permalink
CB-22456 Filling FreeIPa attribute in aws env response
Browse files Browse the repository at this point in the history
  • Loading branch information
daszabo committed Feb 2, 2024
1 parent 750c077 commit 63b0936
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions resources/environments/resource_aws_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ package environments

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/hashicorp/terraform-plugin-log/tflog"

"github.com/cloudera/terraform-provider-cdp/cdp-sdk-go/cdp"
Expand Down Expand Up @@ -150,6 +153,44 @@ func toAwsEnvironmentResource(ctx context.Context, env *environmentsmodels.Envir
}
}
}
if env.Freeipa != nil {
var ipaDiags diag.Diagnostics
var recipeDiags diag.Diagnostics
var recipes types.Set
recipes, recipeDiags = types.SetValueFrom(ctx, types.StringType, env.Freeipa.Recipes)
diags.Append(recipeDiags...)

var freeIpaDetails AWSFreeIpaDetails
model.FreeIpa.As(ctx, &freeIpaDetails, basetypes.ObjectAsOptions{UnhandledNullAsEmpty: true, UnhandledUnknownAsEmpty: true})

var instanceType string
if len(env.Freeipa.Instances) > 0 {
instanceType = env.Freeipa.Instances[0].InstanceType
} else {
instanceType = freeIpaDetails.InstanceType.String()
}

model.FreeIpa, ipaDiags = types.ObjectValueFrom(ctx, map[string]attr.Type{
"catalog": types.StringType,
"image_id": types.StringType,
"os": types.StringType,
"instance_count_by_group": types.Int64Type,
"instance_type": types.StringType,
"multi_az": types.BoolType,
"recipes": types.SetType{
ElemType: types.StringType,
},
}, &AWSFreeIpaDetails{
Catalog: freeIpaDetails.Catalog,
ImageID: freeIpaDetails.ImageID,
Os: freeIpaDetails.Os,
InstanceCountByGroup: types.Int64Value(int64(env.Freeipa.InstanceCountByGroup)),
InstanceType: types.StringValue(instanceType),
MultiAz: freeIpaDetails.MultiAz,
Recipes: recipes,
})
diags.Append(ipaDiags...)
}
if env.Network != nil {
model.EndpointAccessGatewayScheme = types.StringValue(env.Network.EndpointAccessGatewayScheme)
model.NetworkCidr = types.StringValue(env.Network.NetworkCidr)
Expand Down

0 comments on commit 63b0936

Please sign in to comment.