-
Notifications
You must be signed in to change notification settings - Fork 48
Onboarding Intake(1/3): Intake Runner #1086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
devanshcache
wants to merge
9
commits into
stackitcloud:main
Choose a base branch
from
stackit-intake:onboard-intake
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,256
−3
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
50e8da2
Resolve conflicts
450efa1
added example of intake runner
f5d35f4
added datasource for intake runner
540b360
Resolve conflicts
edd6e86
Add docs
2fe6a95
Update stackit/internal/services/intake/runner/data_source.go
yago-123 41909c6
Remove region field
51a9ea0
Add description to custom endpoint
801670c
Adjust fields for resource.go (still missing region)
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| 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. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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