Skip to content
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
21 changes: 10 additions & 11 deletions examples/comprehensive/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ resource "galaxy_role" "admin" {
role_description = "Administrative role with full access"
}

# Note: Using hardcoded user values to avoid data source type conversion issues
# In production, you would use data.galaxy_user to look up existing users
# Look up a real user for data product contacts
data "galaxy_users" "all" {}

locals {
admin_user_id = "u-9639270557"
admin_email = "admin@example.com"
admin_user = data.galaxy_users.all.result[0]
}

# ==========================================
Expand Down Expand Up @@ -191,13 +191,12 @@ resource "galaxy_data_product" "customer_360" {
schema_name = "customeranalytics"
catalog_id = galaxy_mysql_catalog.transactional.catalog_id

contacts = []
# contacts = [
# {
# email = local.admin_email
# user_id = local.admin_user_id
# }
# ]
contacts = [
{
email = local.admin_user.email
user_id = local.admin_user.user_id
}
]
}

# ==========================================
Expand Down
20 changes: 10 additions & 10 deletions examples/data_governance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ resource "galaxy_role" "data_engineer" {
role_description = "Role for data engineers"
}

# Note: Using hardcoded user values to avoid data source type conversion issues
# In production, you would use data.galaxy_user to look up existing users
# Look up a real user for data product contacts
data "galaxy_users" "all" {}

locals {
admin_user_id = "u-9639270557"
admin_email = "admin@example.com"
admin_user = data.galaxy_users.all.result[0]
}

# Create required S3 catalog
Expand All @@ -71,8 +71,8 @@ resource "galaxy_data_product" "customer_analytics" {

contacts = [
{
user_id = local.admin_user_id
email = local.admin_email
user_id = local.admin_user.user_id
email = local.admin_user.email
}
]
}
Expand Down Expand Up @@ -142,28 +142,28 @@ resource "galaxy_policy" "read_all" {

# Data sources for governance objects
data "galaxy_data_product" "customer_analytics" {
depends_on = [galaxy_data_product.customer_analytics]
depends_on = [galaxy_data_product.customer_analytics]
data_product_id = galaxy_data_product.customer_analytics.data_product_id
}

data "galaxy_data_products" "all" {}

data "galaxy_tag" "pii" {
depends_on = [galaxy_tag.pii]
tag_id = galaxy_tag.pii.tag_id
tag_id = galaxy_tag.pii.tag_id
}

data "galaxy_tags" "all" {}

data "galaxy_row_filter" "region_filter" {
depends_on = [galaxy_row_filter.customer_region_filter]
depends_on = [galaxy_row_filter.customer_region_filter]
row_filter_id = galaxy_row_filter.customer_region_filter.row_filter_id
}

data "galaxy_row_filters" "all" {}

data "galaxy_column_mask" "ssn" {
depends_on = [galaxy_column_mask.ssn_mask]
depends_on = [galaxy_column_mask.ssn_mask]
column_mask_id = galaxy_column_mask.ssn_mask.column_mask_id
}

Expand Down
14 changes: 7 additions & 7 deletions examples/data_product/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ resource "galaxy_role" "data_product_role" {
role_description = "Role for data product owner"
}

# Note: Using hardcoded user values to avoid data source type conversion issues
# In production, you would use data.galaxy_user to look up existing users
# Look up a real user for data product contacts
data "galaxy_users" "all" {}

locals {
data_product_owner_user_id = "u-9639270557"
data_product_owner_email = "dataowner@example.com"
data_product_owner = data.galaxy_users.all.result[0]
}

# Create tags for the data product
Expand All @@ -108,15 +108,15 @@ resource "galaxy_data_product" "customer_360" {

contacts = [
{
email = local.data_product_owner_email
user_id = local.data_product_owner_user_id
email = local.data_product_owner.email
user_id = local.data_product_owner.user_id
}
]
}

# Data source to read the data product
data "galaxy_data_product" "customer_360" {
depends_on = [galaxy_data_product.customer_360]
depends_on = [galaxy_data_product.customer_360]
data_product_id = galaxy_data_product.customer_360.data_product_id
}

Expand Down
9 changes: 9 additions & 0 deletions internal/provider/bigquery_catalog_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,13 @@ func (d *bigquery_catalogDataSource) updateModelFromResponse(ctx context.Context
if credentialsKey, ok := response["credentialsKey"].(string); ok {
model.CredentialsKey = types.StringValue(credentialsKey)
}
if parentProjectId, ok := response["parentProjectId"].(string); ok {
model.ParentProjectId = types.StringValue(parentProjectId)
}
if projectId, ok := response["projectId"].(string); ok {
model.ProjectId = types.StringValue(projectId)
}
if validate, ok := response["validate"].(bool); ok {
model.Validate = types.BoolValue(validate)
}
}
29 changes: 29 additions & 0 deletions internal/provider/bigquery_catalogs_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,35 @@ func (d *bigquery_catalogsDataSource) mapSingleBigqueryCatalog(ctx context.Conte
} else {
attributes["validate"] = types.BoolNull()
}

// Map credentials key
if credentialsKey, ok := catalogMap["credentialsKey"].(string); ok {
attributes["credentials_key"] = types.StringValue(credentialsKey)
} else {
attributes["credentials_key"] = types.StringNull()
}

// Map parent project ID
if parentProjectId, ok := catalogMap["parentProjectId"].(string); ok {
attributes["parent_project_id"] = types.StringValue(parentProjectId)
} else {
attributes["parent_project_id"] = types.StringNull()
}

// Map project ID
if projectId, ok := catalogMap["projectId"].(string); ok {
attributes["project_id"] = types.StringValue(projectId)
} else {
attributes["project_id"] = types.StringNull()
}

// Map read only
if readOnly, ok := catalogMap["readOnly"].(bool); ok {
attributes["read_only"] = types.BoolValue(readOnly)
} else {
attributes["read_only"] = types.BoolNull()
}

// Create the ResultValue using the constructor
catalog, diags := datasource_bigquery_catalogs.NewResultValue(attributeTypes, attributes)
if diags.HasError() {
Expand Down
12 changes: 6 additions & 6 deletions internal/provider/catalog_metadata_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ func (d *catalog_metadataDataSource) updateModelFromResponse(ctx context.Context
for _, tag := range tags {
if tagMap, ok := tag.(map[string]interface{}); ok {
tagValue := datasource_catalog_metadata.TagsValue{
Name: types.StringValue(""),
TagId: types.StringValue(""),
Name: types.StringNull(),
TagId: types.StringNull(),
}
if name, ok := tagMap["name"].(string); ok {
tagValue.Name = types.StringValue(name)
}
if tagId, ok := tagMap["tag_id"].(string); ok {
if tagId, ok := tagMap["tagId"].(string); ok {
tagValue.TagId = types.StringValue(tagId)
}
tagElements = append(tagElements, tagValue)
Expand Down Expand Up @@ -149,13 +149,13 @@ func (d *catalog_metadataDataSource) updateModelFromResponse(ctx context.Context
for _, contact := range contacts {
if contactMap, ok := contact.(map[string]interface{}); ok {
contactValue := datasource_catalog_metadata.ContactsValue{
Email: types.StringValue(""),
UserId: types.StringValue(""),
Email: types.StringNull(),
UserId: types.StringNull(),
}
if email, ok := contactMap["email"].(string); ok {
contactValue.Email = types.StringValue(email)
}
if userId, ok := contactMap["user_id"].(string); ok {
if userId, ok := contactMap["userId"].(string); ok {
contactValue.UserId = types.StringValue(userId)
}
contactElements = append(contactElements, contactValue)
Expand Down
85 changes: 80 additions & 5 deletions internal/provider/data_product_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
"context"
"fmt"

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

Expand Down Expand Up @@ -78,12 +80,15 @@ func (d *data_productDataSource) Read(ctx context.Context, req datasource.ReadRe
}

// Map response to model
d.updateModelFromResponse(ctx, &config, response)
d.updateModelFromResponse(ctx, &config, response, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}

resp.Diagnostics.Append(resp.State.Set(ctx, &config)...)
}

func (d *data_productDataSource) updateModelFromResponse(ctx context.Context, model *datasource_data_product.DataProductModel, response map[string]interface{}) {
func (d *data_productDataSource) updateModelFromResponse(ctx context.Context, model *datasource_data_product.DataProductModel, response map[string]interface{}, diags *diag.Diagnostics) {
// Map response fields to model
if dataProductId, ok := response["dataProductId"].(string); ok {
model.DataProductId = types.StringValue(dataProductId)
Expand Down Expand Up @@ -140,9 +145,79 @@ func (d *data_productDataSource) updateModelFromResponse(ctx context.Context, mo
model.Catalog = catalogValue
}

// Map contacts and links lists - use correct types
model.Contacts = types.ListNull(datasource_data_product.ContactsValue{}.Type(ctx))
model.Links = types.ListNull(datasource_data_product.LinksValue{}.Type(ctx))
// Map contacts from response
if contacts, ok := response["contacts"].([]interface{}); ok && len(contacts) > 0 {
contactsList := make([]datasource_data_product.ContactsValue, 0, len(contacts))
for _, contactInterface := range contacts {
if contactMap, ok := contactInterface.(map[string]interface{}); ok {
attrTypes := datasource_data_product.ContactsValue{}.AttributeTypes(ctx)
attrs := map[string]attr.Value{}
if email, ok := contactMap["email"].(string); ok {
attrs["email"] = types.StringValue(email)
} else {
attrs["email"] = types.StringNull()
}
if userId, ok := contactMap["userId"].(string); ok {
attrs["user_id"] = types.StringValue(userId)
} else {
attrs["user_id"] = types.StringNull()
}
contactValue, d := datasource_data_product.NewContactsValue(attrTypes, attrs)
diags.Append(d...)
if !d.HasError() {
contactsList = append(contactsList, contactValue)
}
}
}
contactsListValue, d := types.ListValueFrom(ctx, datasource_data_product.ContactsValue{}.Type(ctx), contactsList)
diags.Append(d...)
if !d.HasError() {
model.Contacts = contactsListValue
}
} else {
contactsListValue, d := types.ListValueFrom(ctx, datasource_data_product.ContactsValue{}.Type(ctx), []datasource_data_product.ContactsValue{})
diags.Append(d...)
if !d.HasError() {
model.Contacts = contactsListValue
}
}

// Map links from response
if links, ok := response["links"].([]interface{}); ok && len(links) > 0 {
linksList := make([]datasource_data_product.LinksValue, 0, len(links))
for _, linkInterface := range links {
if linkMap, ok := linkInterface.(map[string]interface{}); ok {
attrTypes := datasource_data_product.LinksValue{}.AttributeTypes(ctx)
attrs := map[string]attr.Value{}
if name, ok := linkMap["name"].(string); ok {
attrs["name"] = types.StringValue(name)
} else {
attrs["name"] = types.StringNull()
}
if uri, ok := linkMap["uri"].(string); ok {
attrs["uri"] = types.StringValue(uri)
} else {
attrs["uri"] = types.StringNull()
}
linkValue, d := datasource_data_product.NewLinksValue(attrTypes, attrs)
diags.Append(d...)
if !d.HasError() {
linksList = append(linksList, linkValue)
}
}
}
linksListValue, d := types.ListValueFrom(ctx, datasource_data_product.LinksValue{}.Type(ctx), linksList)
diags.Append(d...)
if !d.HasError() {
model.Links = linksListValue
}
} else {
linksListValue, d := types.ListValueFrom(ctx, datasource_data_product.LinksValue{}.Type(ctx), []datasource_data_product.LinksValue{})
diags.Append(d...)
if !d.HasError() {
model.Links = linksListValue
}
}

// Map created by and modified by
if createdBy, ok := response["createdBy"].(map[string]interface{}); ok {
Expand Down
Loading
Loading