Onboarding Intake(1/3): Intake Runner#1086
Onboarding Intake(1/3): Intake Runner#1086devanshcache wants to merge 23 commits intostackitcloud:mainfrom
Conversation
| @@ -0,0 +1,160 @@ | |||
| package runner_test | |||
There was a problem hiding this comment.
Could you move this file please to stackit/internal/services/intake/intake_acc_test.go please?
We have one acc test for each service usually. See https://github.com/stackitcloud/terraform-provider-stackit/blob/da2bb41b1e1c702e8aa53ae5221f5a49bd6a9251/stackit/internal/services/git/git_acc_test.go for reference 😅
| } | ||
|
|
||
| func testAccIntakeRunnerConfigFull(name, description string, maxKib, maxPerHour int) string { | ||
| return fmt.Sprintf(` |
There was a problem hiding this comment.
Please specify the test config as a terraform file and embed it into the test like we have it in most places:
There was a problem hiding this comment.
You can then specify your test variables like that:
| resource.TestCheckResourceAttr(intakeRunnerResource, "description", ""), | ||
| resource.TestCheckResourceAttr(intakeRunnerResource, "labels.%", "0"), | ||
| ), | ||
| }, |
There was a problem hiding this comment.
Please also test the datasource within your acc test, see
terraform-provider-stackit/stackit/internal/services/git/git_acc_test.go
Lines 87 to 137 in da2bb41
| @@ -0,0 +1,34 @@ | |||
| --- | |||
| # generated by https://github.com/hashicorp/terraform-plugin-docs | |||
| page_title: "stackit_intake_runner Resource - stackit" | |||
There was a problem hiding this comment.
docs and examples for the datasource are missing
| stringplanmodifier.RequiresReplace(), | ||
| }, | ||
| Validators: []validator.String{ | ||
| stringvalidator.OneOf("eu01"), // Currently Intake supports only EU01 region |
There was a problem hiding this comment.
This won't prevent the default_region in the provider configuration to not be eu02 😉
| model.Labels = labels | ||
| } | ||
|
|
||
| if runnerResp.Id != nil && *runnerResp.Id == "" { |
There was a problem hiding this comment.
| if runnerResp.Id != nil && *runnerResp.Id == "" { | |
| if runnerResp.Id != nil || *runnerResp.Id == "" { |
There was a problem hiding this comment.
Switched to:
if runnerResp.Id == nil || *runnerResp.Id == "" {
| } | ||
| model.Name = types.StringPointerValue(runnerResp.DisplayName) | ||
| if runnerResp.Description == nil { | ||
| model.Description = types.StringValue("") |
There was a problem hiding this comment.
This whole condition shouldn't be needed. The following line should be enough
model.Description = types.StringPointerValue(runnerResp.Description)| return nil | ||
| } | ||
|
|
||
| // Build CreateBarPayload from provider's model |
There was a problem hiding this comment.
| // Build CreateBarPayload from provider's model | |
| // Build CreateIntakeRunnerPayload from provider's model |
either adjust the example comments from the contribution guide or remove them 😅
| // Handle optional fields | ||
| if !model.Description.IsUnknown() || model.Description.IsNull() { | ||
| if model.Description.IsNull() { | ||
| payload.Description = sdkUtils.Ptr("") |
There was a problem hiding this comment.
What's the point of this? Sending an empty string? Just leave it out of the payload, it's optional 😄
|
|
||
| payload := &intake.UpdateIntakeRunnerPayload{} | ||
|
|
||
| if !model.Name.IsUnknown() { |
There was a problem hiding this comment.
| if !model.Name.IsUnknown() { | |
I would leave this out. Display name is marked as required for the create request, you'll always have to send it.
| payload.DisplayName = conversion.StringValueToPointer(model.Name) | ||
| } | ||
|
|
||
| if !model.MaxMessageSizeKiB.IsUnknown() { |
| payload.MaxMessageSizeKiB = conversion.Int64ValueToPointer(model.MaxMessageSizeKiB) | ||
| } | ||
|
|
||
| if !model.MaxMessagesPerHour.IsUnknown() { |
| if !model.Labels.IsUnknown() { | ||
| if model.Labels.IsNull() { | ||
| labels = map[string]string{} | ||
| payload.Labels = &labels |
There was a problem hiding this comment.
labels are optional, just leave them out of the payload...
| }, | ||
| "intake_custom_endpoint": schema.StringAttribute{ | ||
| Optional: true, | ||
| Description: descriptions["intake_custom_endpoint"], |
There was a problem hiding this comment.
You will have to add your description to the descriptions slice...
| }, | ||
| "region": schema.StringAttribute{ | ||
| Description: descriptions["region"], | ||
| Required: true, |
There was a problem hiding this comment.
Why is the region required? It should use the default_region value from the provider configuration as a fallback value, just as all our datasource implementations do.
| // Try to find the runner | ||
| _, err := client.GetIntakeRunner(ctx, rs.Primary.Attributes["project_id"], rs.Primary.Attributes["region"], rs.Primary.Attributes["runner_id"]).Execute() | ||
| if err == nil { | ||
| return fmt.Errorf("intake runner with ID %s still exists", rs.Primary.ID) |
There was a problem hiding this comment.
If it still exists, delete it 😉
| var err error | ||
| if testutil.IntakeCustomEndpoint == "" { | ||
| client, err = intake.NewAPIClient( | ||
| sdkConfig.WithRegion("eu01"), |
There was a problem hiding this comment.
| sdkConfig.WithRegion("eu01"), | |
This shouldn't be needed. It's only needed because you have two region parameters in your API URLs:
https://intake.api.eu01.stackit.cloud/v1beta/projects/{projectId}/regions/{regionId}/intake-runners
One in the hostname and one in the URL path. The one in the hostname is redundant and shouldn't be there 😅
89b2fc8 to
540b360
Compare
|
@yago-123 could you please resolve the comments you adressed already? I will only start with another review as soon as all open comments are resolved. |
|
And please check that failing CI pipeline. Maybe run a |
Yes! notice this is still in progress though |
9d5b54d to
3922287
Compare
|
@rubenhoenle this is ready to be reviewed 🫡 |
|
@yago-123 CI pipeline is failing |
3922287 to
a2fdb55
Compare
# Conflicts: # go.mod # go.sum # stackit/internal/testutil/testutil.go # stackit/provider.go # Conflicts: # stackit/internal/testutil/testutil.go
# Conflicts: # go.sum # Conflicts: # go.mod # go.sum
Co-authored-by: Ruben Hönle <git@hoenle.xyz>
a2fdb55 to
e00faf5
Compare
@rubenhoenle this should be ready now |
|
This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it. |
Description
This PR onboards the new STACKIT Intake (ticket) service into the Terraform provider.
Intake is composed of three components:
This PR contains the Intake Runners part only to make a quicker and less overwhelming review.
Checklist
make fmtexamples/directory)make generate-docs(will be checked by CI)make test(will be checked by CI)make lint(will be checked by CI)