in ec/ecresource/snapshotrepositoryresource/read.go [79:132]
func modelToState(model *models.RepositoryConfig, state *modelV0) diag.Diagnostics {
var diags diag.Diagnostics
state.Name = types.StringPointerValue(model.RepositoryName)
config, _ := model.Config.(map[string]interface{})
if repositoryType, ok := config["type"]; ok && repositoryType != nil {
if settingsInterface, ok := config["settings"]; ok && settingsInterface != nil {
settings := settingsInterface.(map[string]interface{})
// Parse into S3 schema if possible, but fall back to Generic when custom settings have been used.
if repositoryType.(string) == "s3" && containsOnlyKnownS3Settings(settings) {
if state.S3 == nil {
state.S3 = &s3RepositoryV0{}
}
if region, ok := settings["region"]; ok && region != nil {
state.S3.Region = types.StringValue(region.(string))
}
if bucket, ok := settings["bucket"]; ok && bucket != nil {
state.S3.Bucket = types.StringValue(bucket.(string))
}
if accessKey, ok := settings["access_key"]; ok && accessKey != nil {
state.S3.AccessKey = types.StringValue(accessKey.(string))
}
if secretKey, ok := settings["secret_key"]; ok && secretKey != nil {
state.S3.SecretKey = types.StringValue(secretKey.(string))
}
if serverSideEncryption, ok := settings["server_side_encryption"]; ok && serverSideEncryption != nil {
state.S3.ServerSideEncryption = types.BoolValue(serverSideEncryption.(bool))
}
if endpoint, ok := settings["endpoint"]; ok && endpoint != nil {
state.S3.Endpoint = types.StringValue(endpoint.(string))
}
if pathStyleAccess, ok := settings["path_style_access"]; ok && pathStyleAccess != nil {
state.S3.PathStyleAccess = types.BoolValue(pathStyleAccess.(bool))
}
} else {
if state.Generic == nil {
state.Generic = &genericRepositoryV0{}
}
state.Generic.Type = types.StringValue(repositoryType.(string))
jsonSettings, err := json.Marshal(settings)
if err != nil {
diags.AddError(
fmt.Sprintf("failed reading snapshot repository: unable to marshal settings - %s", err),
fmt.Sprintf("failed reading snapshot repository: unable to marshal settings - %s", err),
)
} else {
state.Generic.Settings = types.StringValue(string(jsonSettings))
}
}
}
}
return diags
}