Skip to content

Conversation

@cgoetz-inovex
Copy link
Contributor

@cgoetz-inovex cgoetz-inovex commented Dec 12, 2025

  • add resource with examples
  • add data source with examples
  • add acceptance tests

Description

relates to STACKITTPR-448

Checklist

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see examples/ directory)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Acceptance tests got implemented or updated (see e.g. here)
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

- add resource with examples
- add data source with examples
- add acceptance tests
@cgoetz-inovex cgoetz-inovex requested a review from a team as a code owner December 12, 2025 11:04

func (d *logsInstanceDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: features.AddBetaDescription("Logs instance resource schema.", core.Resource),
Copy link
Contributor

@GokceGK GokceGK Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MarkdownDescription: features.AddBetaDescription("Logs instance resource schema.", core.Resource),
MarkdownDescription: features.AddBetaDescription("Logs instance data source schema.", core.Datasource),

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it is still core.Resource

core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading logs instance", fmt.Sprintf("Calling API: %v", err))
return
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ctx = core.LogResponse(ctx)

"acl": schema.ListAttribute{
Description: schemaDescriptions["acl"],
ElementType: types.StringType,
Optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should acl also be the Computed: true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be set on creation/update, not sure if Computed: true would be correct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, as this is an optional field, if user do not defines sth, it might be that there are some server-side defaults. That is why I thought it should be optional: true and computed:true.

But maybe @marceljk, can double check this? :)

Copy link
Contributor

@marceljk marceljk Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Computed isn't needed here. This must only be set, if the backend would set acl to an default value, e.g. an empty list. But when it wasn't set during the creation, the api doesn't sent a value for acl and it remains to null.

Side note:
In some cases it's needed to set Computed and Optional to true. This can cause some issues in ListAttributes, when a user has set a value during creation and removes it then within an update. See https://www.github.com/stackitcloud/terraform-provider-stackit/issues/926

if err != nil {
var oapiErr *oapierror.GenericOpenAPIError
ok := errors.As(err, &oapiErr)
if ok && oapiErr.StatusCode == http.StatusNotFound {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ok && oapiErr.StatusCode == http.StatusNotFound {
if ok && (oapiErr.StatusCode == http.StatusNotFound || oapiErr.StatusCode == http.StatusGone) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gone is not listed as a possible status in the API docs.
What's the reasoning for this change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes it is forgotten to add some status in the docs, I thought we can be on the safe side by adding the check. But it is no critical to add. You can also skip.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have only the http.StatusGone check for the DSA services. https://github.com/search?q=repo%3Astackitcloud%2Fterraform-provider-stackit%20http.StatusGone&type=code

So as long this isn't documented in the api docs of the logs service, I wouldn't add the check

- rename git to logs in example
- add NoSeparator validator for instance-/project-id
- log responses and instance_ids
- rm redundant struct field docs
- mention possible status values in description
- test ConfigureClient
- use ElementsAs
@marceljk
Copy link
Contributor

When I run the following terraform config, the read of the data source fails

resource "stackit_logs_instance" "example" {
  display_name = "mj-test"
  project_id = var.project_id
  retention_days = 1
}

data "stackit_logs_instance" "example" {
  project_id = var.project_id
  instance_id = stackit_logs_instance.example.instance_id
}
╷
│ Error: Provider produced null object
│ 
│ Provider "provider[\"registry.terraform.io/stackitcloud/stackit\"]" produced a null value for data.stackit_logs_instance.example.
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add the examples to the generated docs, you need to rename the folder "stackit_logs" to the resource/datasource name "stackit_logs_instance" and rerun "make generate-docs"

@cgoetz-inovex
Copy link
Contributor Author

When I run the following terraform config, the read of the data source fails

resource "stackit_logs_instance" "example" {
  display_name = "mj-test"
  project_id = var.project_id
  retention_days = 1
}

data "stackit_logs_instance" "example" {
  project_id = var.project_id
  instance_id = stackit_logs_instance.example.instance_id
}
╷
│ Error: Provider produced null object
│ 
│ Provider "provider[\"registry.terraform.io/stackitcloud/stackit\"]" produced a null value for data.stackit_logs_instance.example.
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

thanks, fixed

@github-actions
Copy link

Merging this branch changes the coverage (2 decrease, 2 increase)

Impacted Packages Coverage Δ 🤖
github.com/stackitcloud/terraform-provider-stackit/stackit 1.52% (-0.02%) 👎
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core 21.62% (ø)
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/logs 0.00% (ø)
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/logs/instance 19.76% (+19.76%) 🎉
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/logs/utils 77.78% (+77.78%) 🌟
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil 6.57% (-0.15%) 👎

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core/core.go 21.62% (ø) 37 8 29
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/logs/instance/datasource.go 0.00% (ø) 43 (+43) 0 43 (+43)
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/logs/instance/resource.go 23.81% (+23.81%) 210 (+210) 50 (+50) 160 (+160) 🌟
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/logs/utils/utils.go 77.78% (+77.78%) 9 (+9) 7 (+7) 2 (+2) 🌟
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil/testutil.go 6.57% (-0.15%) 137 (+3) 9 128 (+3) 👎
github.com/stackitcloud/terraform-provider-stackit/stackit/provider.go 1.52% (-0.02%) 132 (+2) 2 130 (+2) 👎

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/logs/instance/resource_test.go
  • github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/logs/logs_acc_test.go
  • github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/logs/utils/utils_test.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants