Skip to content
Open
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
30 changes: 30 additions & 0 deletions docs/data-sources/intake_runner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackit_intake_runner Data Source - stackit"
subcategory: ""
description: |-
Datasource for STACKIT Intake Runner.
---

# stackit_intake_runner (Data Source)

Datasource for STACKIT Intake Runner.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `project_id` (String) STACKIT Project ID to which the runner is associated.
- `runner_id` (String) The runner ID.

### Read-Only

- `description` (String) The description of the runner.
- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`region`,`runner_id`".
- `labels` (Map of String) User-defined labels.
- `max_message_size_kib` (Number) The maximum message size in KiB.
- `max_messages_per_hour` (Number) The maximum number of messages per hour.
- `name` (String) The name of the runner.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Note: AWS specific checks must be skipped as they do not work on STACKIT. For de
- `experiments` (List of String) Enables experiments. These are unstable features without official support. More information can be found in the README. Available Experiments: iam, routing-tables, network
- `git_custom_endpoint` (String) Custom endpoint for the Git service
- `iaas_custom_endpoint` (String) Custom endpoint for the IaaS service
- `intake_custom_endpoint` (String) Custom endpoint for the Intake service
- `kms_custom_endpoint` (String) Custom endpoint for the KMS service
- `loadbalancer_custom_endpoint` (String) Custom endpoint for the Load Balancer service
- `logme_custom_endpoint` (String) Custom endpoint for the LogMe service
Expand Down
54 changes: 54 additions & 0 deletions docs/resources/intake_runner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackit_intake_runner Resource - stackit"
Copy link
Member

Choose a reason for hiding this comment

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

docs and examples for the datasource are missing

subcategory: ""
description: |-
Manages STACKIT Intake Runner.
---

# stackit_intake_runner (Resource)

Manages STACKIT Intake Runner.

## Example Usage

```terraform
resource "stackit_intake_runner" "example" {
project_id = var.project_id
name = "example-runner-full"
description = "An example runner for STACKIT Intake"
max_message_size_kib = 2048
max_messages_per_hour = 1500
labels = {
"created_by" = "terraform-example"
"env" = "production"
}
region = var.region
}

import {
to = stackit_intake_runner.example
id = "${var.project_id},${var.region},${var.runner_id}"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `max_message_size_kib` (Number) The maximum message size in KiB.
- `max_messages_per_hour` (Number) The maximum number of messages per hour.
- `name` (String) The name of the runner.
- `project_id` (String) STACKIT Project ID to which the runner is associated.

### Optional

- `description` (String) The description of the runner.
- `labels` (Map of String) User-defined labels.
- `region` (String) The resource region. If not defined, the provider region is used.

### Read-Only

- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`region`,`runner_id`".
- `runner_id` (String) The runner ID.
17 changes: 17 additions & 0 deletions examples/resources/stackit_intake_runner/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "stackit_intake_runner" "example" {
project_id = var.project_id
name = "example-runner-full"
description = "An example runner for STACKIT Intake"
max_message_size_kib = 2048
max_messages_per_hour = 1500
labels = {
"created_by" = "terraform-example"
"env" = "production"
}
region = var.region
}

import {
to = stackit_intake_runner.example
id = "${var.project_id},${var.region},${var.runner_id}"
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ require (
github.com/hashicorp/terraform-plugin-go v0.29.0
github.com/hashicorp/terraform-plugin-log v0.10.0
github.com/hashicorp/terraform-plugin-testing v1.14.0
github.com/stackitcloud/stackit-sdk-go/core v0.20.1
github.com/stackitcloud/stackit-sdk-go/core v0.21.0
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.9.1
github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.3
github.com/stackitcloud/stackit-sdk-go/services/edge v0.4.0
github.com/stackitcloud/stackit-sdk-go/services/git v0.10.1
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.0
github.com/stackitcloud/stackit-sdk-go/services/intake v0.4.2
github.com/stackitcloud/stackit-sdk-go/services/kms v1.2.0
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.7.0
github.com/stackitcloud/stackit-sdk-go/services/logme v0.25.3
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnBY8=
github.com/skeema/knownhosts v1.3.1/go.mod h1:r7KTdC8l4uxWRyK2TpQZ/1o5HaSzh06ePQNxPwTcfiY=
github.com/stackitcloud/stackit-sdk-go/core v0.20.1 h1:odiuhhRXmxvEvnVTeZSN9u98edvw2Cd3DcnkepncP3M=
github.com/stackitcloud/stackit-sdk-go/core v0.20.1/go.mod h1:fqto7M82ynGhEnpZU6VkQKYWYoFG5goC076JWXTUPRQ=
github.com/stackitcloud/stackit-sdk-go/core v0.21.0 h1:QXZqiaO7U/4IpTkJfzt4dt6QxJzG2uUS12mBnHpYNik=
github.com/stackitcloud/stackit-sdk-go/core v0.21.0/go.mod h1:fqto7M82ynGhEnpZU6VkQKYWYoFG5goC076JWXTUPRQ=
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.11.0 h1:4YFY5PG4vP/NiEP1uxCwh+kQHEU7iHG6syuFD7NPqcw=
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.11.0/go.mod h1:v4xdRA5P8Vr+zLdHh+ODgspN0WJG04wLImIJoYjrPK4=
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.9.1 h1:PiNC8VmLqi1WUnBSPefjDXThD43Fvb87p+Y6H8onGA0=
Expand All @@ -163,6 +163,8 @@ github.com/stackitcloud/stackit-sdk-go/services/git v0.10.1 h1:3JKXfI5hdcXcRVBjU
github.com/stackitcloud/stackit-sdk-go/services/git v0.10.1/go.mod h1:3nTaj8IGjNNGYUD2CpuXkXwc5c4giTUmoPggFhjVFxo=
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.0 h1:U/x0tc487X9msMS5yZYjrBAAKrCx87Trmt0kh8JiARA=
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.0/go.mod h1:6+5+RCDfU7eQN3+/SGdOtx7Bq9dEa2FrHz/jflgY1M4=
github.com/stackitcloud/stackit-sdk-go/services/intake v0.4.2 h1:xywfPSTBV6lqcnueI++KsyWvnZTKCfoCVp8/kzT/RXE=
github.com/stackitcloud/stackit-sdk-go/services/intake v0.4.2/go.mod h1:Ki7BldvSi1f5Lhy7iDeBkAhUvgXPCSAsaqFuxrkPDpg=
github.com/stackitcloud/stackit-sdk-go/services/kms v1.2.0 h1:Ar2n9GKmrTN80G/Ta1R+fL5aX5nEoxL6ODVJl3emzho=
github.com/stackitcloud/stackit-sdk-go/services/kms v1.2.0/go.mod h1:sHMFoYvVrkRZcH13DkLvp48nW+ssRVVVuwqJHDGpa5M=
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.7.0 h1:ZyaB4jL71p+FWI/cXgP+p6t4iw1oAeGbLLOz4cs3dmI=
Expand Down
1 change: 1 addition & 0 deletions stackit/internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type ProviderData struct {
EdgeCloudCustomEndpoint string
GitCustomEndpoint string
IaaSCustomEndpoint string
IntakeCustomEndpoint string
KMSCustomEndpoint string
LoadBalancerCustomEndpoint string
LogMeCustomEndpoint string
Expand Down
162 changes: 162 additions & 0 deletions stackit/internal/services/intake/runner/data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package runner

import (
"context"
"errors"
"fmt"
"net/http"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
intakeUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/intake/utils"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"

"github.com/stackitcloud/stackit-sdk-go/services/intake"
)

// Ensure the implementation satisfies the expected interfaces
var (
_ datasource.DataSource = &runnerDataSource{}
)

// NewRunnerDataSource is a helper function to simplify the provider implementation
func NewRunnerDataSource() datasource.DataSource {
return &runnerDataSource{}
}

type runnerDataSource struct {
client *intake.APIClient
}

func (r *runnerDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_intake_runner"
}

// Configure adds the provider configured client to the data source
func (r *runnerDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
providerData, ok := conversion.ParseProviderData(ctx, req.ProviderData, &resp.Diagnostics)
if !ok {
return
}

apiClient := intakeUtils.ConfigureClient(ctx, &providerData, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}
r.client = apiClient
tflog.Info(ctx, "Intake runner client configured for data source")
}

// Schema defines the schema for the data source
func (r *runnerDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
descriptions := map[string]string{
"main": "Datasource for STACKIT Intake Runner.",
"id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`region`,`runner_id`\".",
"project_id": "STACKIT Project ID to which the runner is associated.",
"runner_id": "The runner ID.",
"name": "The name of the runner.",
"description": "The description of the runner.",
"labels": "User-defined labels.",
"max_message_size_kib": "The maximum message size in KiB.",
"max_messages_per_hour": "The maximum number of messages per hour.",
}

resp.Schema = schema.Schema{
Description: descriptions["main"],
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Description: descriptions["id"],
Computed: true,
},
"project_id": schema.StringAttribute{
Description: descriptions["project_id"],
Required: true,
Validators: []validator.String{
validate.UUID(),
validate.NoSeparator(),
},
},
"runner_id": schema.StringAttribute{
Description: descriptions["runner_id"],
Required: true,
Validators: []validator.String{
validate.UUID(),
validate.NoSeparator(),
},
},
"name": schema.StringAttribute{
Description: descriptions["name"],
Computed: true,
},
"description": schema.StringAttribute{
Description: descriptions["description"],
Computed: true,
},
"labels": schema.MapAttribute{
Description: descriptions["labels"],
ElementType: types.StringType,
Computed: true,
},
"max_message_size_kib": schema.Int64Attribute{
Description: descriptions["max_message_size_kib"],
Computed: true,
},
"max_messages_per_hour": schema.Int64Attribute{
Description: descriptions["max_messages_per_hour"],
Computed: true,
},
},
}
}

// Read refreshes the Terraform state with the latest data.
func (r *runnerDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { // nolint:gocritic // function signature required by Terraform
var model Model
resp.Diagnostics.Append(req.Config.Get(ctx, &model)...)
if resp.Diagnostics.HasError() {
return
}

ctx = core.InitProviderContext(ctx)

projectId := model.ProjectId.ValueString()
region := model.Region.ValueString()
runnerId := model.RunnerId.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "region", region)
ctx = tflog.SetField(ctx, "runner_id", runnerId)

runnerResp, err := r.client.GetIntakeRunner(ctx, projectId, region, runnerId).Execute()
if err != nil {
var oapiErr *oapierror.GenericOpenAPIError
if errors.As(err, &oapiErr) {
if oapiErr.StatusCode == http.StatusNotFound {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading runner", fmt.Sprintf("Runner with ID %s not found in project %s and region %s", runnerId, projectId, region))
return
}
}
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading runner", fmt.Sprintf("Calling API: %v", err))
return
}

ctx = core.LogResponse(ctx)

err = mapFields(runnerResp, &model)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading runner", fmt.Sprintf("Processing API payload: %v", err))
return
}

// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, model)...)
if resp.Diagnostics.HasError() {
return
}
tflog.Info(ctx, "Intake runner read")
}
Loading