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
description = "Example description"
}

# Only use the import statement, if you want to import an existing git resource
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
# Only use the import statement, if you want to import an existing git resource
# Only use the import statement, if you want to import an existing logs instance

@@ -0,0 +1,23 @@
resource "stackit_logs_instance" "git" {
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
resource "stackit_logs_instance" "git" {
resource "stackit_logs_instance" "logs" {

retention_days = 30
}

resource "stackit_logs_instance" "logs" {
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
resource "stackit_logs_instance" "logs" {
resource "stackit_logs_instance" "logs2" {


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),

func (d *logsInstanceDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: features.AddBetaDescription("Logs instance resource schema.", core.Resource),
Description: fmt.Sprintf("Logs instance resource schema. %s", core.ResourceRegionFallbackDocstring),
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
Description: fmt.Sprintf("Logs instance resource schema. %s", core.ResourceRegionFallbackDocstring),
Description: fmt.Sprintf("Logs instance data source schema. %s", core.DatasourceRegionFallbackDocstring),

"instance_id": schema.StringAttribute{
Description: schemaDescriptions["instance_id"],
Required: true,
Validators: []validator.String{validate.UUID()},
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
Validators: []validator.String{validate.UUID()},
Validators: []validator.String{
validate.UUID(),
validate.NoSeparator(),
},

},
"project_id": schema.StringAttribute{
Description: schemaDescriptions["project_id"],
Required: true,
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
Required: true,
Required: true,
Validators: []validator.String{
validate.UUID(),
validate.NoSeparator(),
},

Description: schemaDescriptions["description"],
Computed: true,
},
"display_name": schema.StringAttribute{
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we also need here a validator like

			Validators: []validator.String{
				stringvalidator.LengthAtLeast(1),
			},

Description: schemaDescriptions["retention_days"],
Computed: true,
},
"status": schema.StringAttribute{
Copy link
Contributor

Choose a reason for hiding this comment

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

Status has enum values. It will be good if we can mention the values in the description.
Sth like
statusOptions := []string{"active","deleting","reconciling"}
... utils.FormatPossibleValues(statusOptions)...

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)

if resp.Diagnostics.HasError() {
return
}
tflog.Info(ctx, "Logs Instance read")
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
tflog.Info(ctx, "Logs Instance read")
tflog.Info(ctx, fmt.Sprintf("read Logs instance %s", instanceID))

"id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`region`,`instance_id`\".",
"instance_id": "The Logs instance ID",
"region": "STACKIT region name the resource is located in. If not defined, the provider region is used.",
"project_id": "STACKIT project ID associated with the logs instance",
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
"project_id": "STACKIT project ID associated with the logs instance",
"project_id": "STACKIT project ID associated with the Logs instance",

"instance_id": "The Logs instance ID",
"region": "STACKIT region name the resource is located in. If not defined, the provider region is used.",
"project_id": "STACKIT project ID associated with the logs instance",
"acl": "ACL entries for the logs instance",
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
"acl": "ACL entries for the logs instance",
"acl": "The access control list for the Logs instance",

"region": "STACKIT region name the resource is located in. If not defined, the provider region is used.",
"project_id": "STACKIT project ID associated with the logs instance",
"acl": "ACL entries for the logs instance",
"created": "Time when the distribution was created",
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
"created": "Time when the distribution was created",
"created": "The date and time the creation of the Logs instance was triggered",

"query_range_url": "The Logs instance's query range URL",
"query_url": "The Logs instance's query URL",
"retention_days": "The log retention time in days",
"status": "The status of the Logs instance",
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned in the datasource, it will be good to mention the possible enum values

"status": "The status of the Logs instance",
}

type Model struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think comments are not needed for the fields. Descriptions are already very clear.

Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Description: schemaDescriptions["id"],
Computed: true,
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
Computed: true,
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},

"instance_id": schema.StringAttribute{
Description: schemaDescriptions["instance_id"],
Computed: true,
Validators: []validator.String{validate.UUID()},
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
Validators: []validator.String{validate.UUID()},
Validators: []validator.String{
validate.UUID(),
validate.NoSeparator(),
},

Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
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
},
},
Validators: []validator.String{
validate.UUID(),
validate.NoSeparator(),
},

"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.

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?

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.

I think we are missing this ctx = core.LogResponse(ctx)

if resp.Diagnostics.HasError() {
return
}
tflog.Info(ctx, "Logs Instance read")
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
tflog.Info(ctx, "Logs Instance read")
tflog.Info(ctx, fmt.Sprintf("read logs instance %s", instanceID))

if resp.Diagnostics.HasError() {
return
}
tflog.Info(ctx, "Logs Instance updated")
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
tflog.Info(ctx, "Logs Instance updated")
tflog.Info(ctx, fmt.Sprintf("update logs instance %s", instanceID))

return nil, fmt.Errorf("missing model")
}

var acls []string
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can use here .ElementsAs and avoid that code block. Sth like the following maybe

	if !(model.ACL.IsNull() || model.ACL.IsUnknown()) {
		var acl []string
		aclDiags := model.ACL.ElementsAs(ctx, &acl, false)
		diags.Append(aclDiags...)
		if !aclDiags.HasError() {
			payload.Acl = &acl
		}
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

way nicer, thanks!

return nil, fmt.Errorf("missing model")
}

var acls []string
Copy link
Contributor

Choose a reason for hiding this comment

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

If you decide to change, same here like i mentioned in CreatePayload

"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
)

func ConfigureClient(ctx context.Context, providerData *core.ProviderData, diags *diag.Diagnostics) *logs.APIClient {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing unit test for this one

"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
)

func ConfigureClient(ctx context.Context, providerData *core.ProviderData, diags *diag.Diagnostics) *logs.APIClient {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing unit test for this one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

duplicated comment?

- 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
@github-actions
Copy link

github-actions bot commented Jan 8, 2026

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

Impacted Packages Coverage Δ 🤖
github.com/stackitcloud/terraform-provider-stackit/stackit 1.54% (-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.84% (+19.84%) 🎉
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.72% (-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% (ø) 42 (+42) 0 42 (+42)
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.72% (-0.15%) 134 (+3) 9 125 (+3) 👎
github.com/stackitcloud/terraform-provider-stackit/stackit/provider.go 1.54% (-0.02%) 130 (+2) 2 128 (+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.

3 participants