Skip to content

add fields for ai update - #102

Merged
michaelst merged 2 commits into
mainfrom
ai-update
Jul 2, 2026
Merged

michaelst merged 2 commits into
mainfrom
ai-update

Conversation

@michaelst

Copy link
Copy Markdown
Contributor

No description provided.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Add AI access controls to Querydesk database resource

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 20-40 Minutes

Grey Divider

AI Description

• Add AI opt-in flags and row limits on the database resource.
• Add per-credential AI permission and optional query timeout support.
• Update docs, examples, and acceptance tests to cover new attributes.
Diagram

graph TD
  A["Terraform config"] --> B["Database resource"] --> C["Provider model+schema"] --> D["DevHub client models"] --> E["DevHub API"]
  F["Docs + examples"] --> A
  G["Acceptance tests"] --> B

  subgraph Legend
    direction LR
    _cfg["Config / HCL"] ~~~ _prov["Provider component"] ~~~ _api["External API"]
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Model timeout as duration string (e.g., "30s")
  • ➕ More idiomatic for Terraform users (aligns with time.ParseDuration style).
  • ➕ Avoids ambiguity around units (seconds vs milliseconds).
  • ➖ Requires parsing/validation and potential API conversion logic.
  • ➖ Could be a breaking change if the API/clients expect numeric seconds.

Recommendation: Current approach (int seconds for timeout, bool flags for AI access) is reasonable and matches the apparent API contract. If users frequently need sub-second or explicit units, consider a future enhancement to accept duration strings while still storing seconds in the API model.

Files changed (5) +104 / -16

Enhancement (2) +61 / -0
models.goAdd AI fields to API models +4/-0

Add AI fields to API models

• Extends Database and DatabaseCredential client structs with ai_enabled/ai_max_rows and ai_allowed/timeout JSON fields so requests/responses can carry AI settings.

internal/client/models.go

devhub_querydesk_database_resource.goExpose AI attributes in schema and map to API +57/-0

Expose AI attributes in schema and map to API

• Adds new Terraform schema attributes (ai_enabled, ai_max_rows, ai_allowed, timeout) with defaults for database-level AI settings, maps them into API create/update payloads, and reads them back into state including nil-safe timeout handling.

internal/provider/devhub_querydesk_database_resource.go

Tests (1) +23 / -8
devhub_querydesk_database_resource_test.goAdd acceptance coverage for AI fields +23/-8

Add acceptance coverage for AI fields

• Updates the acceptance test config helper to parameterize AI settings and adds assertions for ai_enabled/ai_max_rows, credential ai_allowed, and presence/absence of credential timeout across create and update steps.

internal/provider/devhub_querydesk_database_resource_test.go

Documentation (2) +20 / -8
querydesk_database.mdDocument AI database and credential fields +12/-4

Document AI database and credential fields

• Updates the resource docs to include ai_enabled/ai_max_rows on the database and ai_allowed/timeout on credentials, and extends the example snippet accordingly.

docs/resources/querydesk_database.md

resource.tfExpand example with AI settings +8/-4

Expand example with AI settings

• Updates the example resource configuration to demonstrate enabling AI, setting a max row limit, allowing AI on a credential, and setting a credential timeout.

examples/resources/devhub_querydesk_database/resource.tf

@qodo-code-review

qodo-code-review Bot commented Jul 2, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Update ignores API response ✓ Resolved 🐞 Bug ☼ Reliability
Description
In databaseResource.Update, the provider sends ai_enabled/ai_max_rows and per-credential
ai_allowed/timeout to the API but then writes state from the plan and only backfills credential IDs,
discarding any server-canonicalized values for these fields.
Code

internal/provider/devhub_querydesk_database_resource.go[R413-422]

		credentials = append(credentials, devhub.DatabaseCredential{
			Id:                credential.Id.ValueString(),
			Username:          credential.Username.ValueString(),
			Password:          credential.Password.ValueString(),
			Hostname:          credential.Hostname.ValueString(),
			ReviewsRequired:   int(credential.ReviewsRequired.ValueInt64()),
			DefaultCredential: credential.DefaultCredential.ValueBool(),
+			AiAllowed:         credential.AiAllowed.ValueBool(),
+			Timeout:           timeout,
		})
Evidence
Update() includes the new AI fields in the API request payload, but after receiving database from
UpdateDatabase, it only copies credential IDs and then sets state from plan, unlike Read() which
maps all fields (including AI fields and timeout) from the server response into state.

internal/provider/devhub_querydesk_database_resource.go[413-475]
internal/provider/devhub_querydesk_database_resource.go[328-386]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`databaseResource.Update` calls `UpdateDatabase(...)` and receives an updated `database` object, but it only uses it to backfill credential IDs and then persists `plan` into state. This can immediately lose server-returned/canonical values for new AI fields (`ai_enabled`, `ai_max_rows`, `credentials[*].ai_allowed`, `credentials[*].timeout`) as well as other computed credential fields.

### Issue Context
The `Read` method already contains the mapping logic from `devhub.Database` -> `databaseResourceModel`. After `UpdateDatabase`, state should be hydrated from the returned `database` (or `Read` should be invoked) to ensure Terraform state reflects the server.

### Fix Focus Areas
- internal/provider/devhub_querydesk_database_resource.go[431-475]
- internal/provider/devhub_querydesk_database_resource.go[328-386]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Timeout not saved on create ✓ Resolved 🐞 Bug ≡ Correctness
Description
In databaseResource.Create, the provider hydrates state from the API response for some credential
fields (id/default_credential/ai_allowed) but never copies back the API-returned timeout, so state
is written with the planned timeout even if the server returns a different value.
Code

internal/provider/devhub_querydesk_database_resource.go[R286-290]

	for index, credential := range database.Credentials {
		plan.Credentials[index].Id = types.StringValue(credential.Id)
		plan.Credentials[index].DefaultCredential = types.BoolValue(credential.DefaultCredential)
+		plan.Credentials[index].AiAllowed = types.BoolValue(credential.AiAllowed)
Evidence
Create() sets state from the plan after selectively copying some credential fields from the API
response, but it never maps the returned Timeout; Read() explicitly maps Timeout from the API
response into state, demonstrating that Timeout is intended to be persisted from the server
representation.

internal/provider/devhub_querydesk_database_resource.go[286-301]
internal/provider/devhub_querydesk_database_resource.go[364-382]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`databaseResource.Create` updates `plan.Credentials[index]` from the `database.Credentials` API response, but it does not set `plan.Credentials[index].Timeout`. Since the function then writes state from `plan`, the credential timeout in state can diverge from the server's returned value.

### Issue Context
The `Read` path already contains the correct mapping logic for `credential.Timeout` -> `types.Int64Null()/types.Int64Value(...)`, which can be reused.

### Fix Focus Areas
- internal/provider/devhub_querydesk_database_resource.go[286-292]
- internal/provider/devhub_querydesk_database_resource.go[364-382]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Comment thread internal/provider/devhub_querydesk_database_resource.go Outdated
Comment thread internal/provider/devhub_querydesk_database_resource.go
@michaelst
michaelst merged commit fd95aa9 into main Jul 2, 2026
13 checks passed
@michaelst
michaelst deleted the ai-update branch July 2, 2026 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant