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
12 changes: 12 additions & 0 deletions examples/full/warehouse/aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ resource "clickhouse_service" "primary" {
}
}

data "clickhouse_api_key_id" "self" {
}

resource "clickhouse_service" "secondary" {
warehouse_id = clickhouse_service.primary.warehouse_id
readonly = true
Expand All @@ -61,6 +64,15 @@ resource "clickhouse_service" "secondary" {
}
]

query_api_endpoints = {
api_key_ids = [
data.clickhouse_api_key_id.self.id
]
roles = [
"sql_console_admin"
]
}

min_replica_memory_gb = 8
max_replica_memory_gb = 120
}
80 changes: 40 additions & 40 deletions pkg/resource/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,46 +992,6 @@ func (r *ServiceResource) Create(ctx context.Context, req resource.CreateRequest
}
}

// Set query api endpoints
if !plan.QueryAPIEndpoints.IsNull() {
qae := models.QueryAPIEndpoints{}
diag := plan.QueryAPIEndpoints.As(ctx, &qae, basetypes.ObjectAsOptions{
UnhandledNullAsEmpty: false,
UnhandledUnknownAsEmpty: false,
})
if diag.HasError() {
resp.Diagnostics.Append(diag.Errors()...)
return
}

roles := make([]string, 0)
diag = qae.Roles.ElementsAs(ctx, &roles, false)
if diag.HasError() {
resp.Diagnostics.Append(diag.Errors()...)
return
}

keys := make([]string, 0)
diag = qae.APIKeyIDs.ElementsAs(ctx, &keys, false)
if diag.HasError() {
resp.Diagnostics.Append(diag.Errors()...)
return
}

_, err := r.client.CreateQueryEndpoint(ctx, s.Id, api.ServiceQueryEndpoint{
Roles: roles,
OpenApiKeys: keys,
AllowedOrigins: qae.AllowedOrigins.ValueString(),
})
if err != nil {
resp.Diagnostics.AddError(
"Error setting service query API endpoints",
"Could not set service query API endpoints, unexpected error: "+err.Error(),
)
return
}
}

// Set backup settings.
if !plan.BackupConfiguration.IsNull() && !plan.BackupConfiguration.IsUnknown() {
bc := models.BackupConfiguration{}
Expand Down Expand Up @@ -1063,6 +1023,46 @@ func (r *ServiceResource) Create(ctx context.Context, req resource.CreateRequest
}
}

// Set query api endpoints
if !plan.QueryAPIEndpoints.IsNull() {
qae := models.QueryAPIEndpoints{}
diag := plan.QueryAPIEndpoints.As(ctx, &qae, basetypes.ObjectAsOptions{
UnhandledNullAsEmpty: false,
UnhandledUnknownAsEmpty: false,
})
if diag.HasError() {
resp.Diagnostics.Append(diag.Errors()...)
return
}

roles := make([]string, 0)
diag = qae.Roles.ElementsAs(ctx, &roles, false)
if diag.HasError() {
resp.Diagnostics.Append(diag.Errors()...)
return
}

keys := make([]string, 0)
diag = qae.APIKeyIDs.ElementsAs(ctx, &keys, false)
if diag.HasError() {
resp.Diagnostics.Append(diag.Errors()...)
return
}

_, err := r.client.CreateQueryEndpoint(ctx, s.Id, api.ServiceQueryEndpoint{
Roles: roles,
OpenApiKeys: keys,
AllowedOrigins: qae.AllowedOrigins.ValueString(),
})
if err != nil {
resp.Diagnostics.AddError(
"Error setting service query API endpoints",
"Could not set service query API endpoints, unexpected error: "+err.Error(),
)
return
}
}

// Map response body to schema and populate Computed attribute values
plan.ID = types.StringValue(s.Id)
err = r.syncServiceState(ctx, &plan, true)
Expand Down
Loading