-
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
base: main
Are you sure you want to change the base?
Conversation
| @@ -0,0 +1,160 @@ | |||
| package runner_test | |||
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please specify the test config as a terraform file and embed it into the test like we have it in most places:
| //go:embed testdata/resource-min.tf | |
| var resourceMin string | |
| //go:embed testdata/resource-max.tf | |
| var resourceMax string |
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.
You can then specify your test variables like that:
| var testConfigVarsMin = config.Variables{ | |
| "project_id": config.StringVariable(testutil.ProjectId), | |
| "name": config.StringVariable(nameMin), | |
| } | |
| var testConfigVarsMax = config.Variables{ | |
| "project_id": config.StringVariable(testutil.ProjectId), | |
| "name": config.StringVariable(nameMax), | |
| "acl": config.StringVariable("192.168.0.0/16"), | |
| "flavor": config.StringVariable("git-100"), | |
| } |
| resource.TestCheckResourceAttr(intakeRunnerResource, "description", ""), | ||
| resource.TestCheckResourceAttr(intakeRunnerResource, "labels.%", "0"), | ||
| ), | ||
| }, |
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.
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
| // Data source | |
| { | |
| ConfigVariables: testConfigVarsMin, | |
| Config: fmt.Sprintf(` | |
| %s | |
| data "stackit_git" "git" { | |
| project_id = stackit_git.git.project_id | |
| instance_id = stackit_git.git.instance_id | |
| } | |
| `, testutil.GitProviderConfig()+resourceMin, | |
| ), | |
| Check: resource.ComposeAggregateTestCheckFunc( | |
| // Instance | |
| resource.TestCheckResourceAttr("data.stackit_git.git", "project_id", testutil.ConvertConfigVariable(testConfigVarsMin["project_id"])), | |
| resource.TestCheckResourceAttrPair( | |
| "stackit_git.git", "project_id", | |
| "data.stackit_git.git", "project_id", | |
| ), | |
| resource.TestCheckResourceAttrPair( | |
| "stackit_git.git", "instance_id", | |
| "data.stackit_git.git", "instance_id", | |
| ), | |
| resource.TestCheckResourceAttrPair( | |
| "stackit_git.git", "name", | |
| "data.stackit_git.git", "name", | |
| ), | |
| resource.TestCheckResourceAttrPair( | |
| "stackit_git.git", "url", | |
| "data.stackit_git.git", "url", | |
| ), | |
| resource.TestCheckResourceAttrPair( | |
| "stackit_git.git", "version", | |
| "data.stackit_git.git", "version", | |
| ), | |
| resource.TestCheckResourceAttrPair( | |
| "stackit_git.git", "created", | |
| "data.stackit_git.git", "created", | |
| ), | |
| resource.TestCheckResourceAttrPair( | |
| "stackit_git.git", "consumed_object_storage", | |
| "data.stackit_git.git", "consumed_object_storage", | |
| ), | |
| resource.TestCheckResourceAttrPair( | |
| "stackit_git.git", "consumed_disk", | |
| "data.stackit_git.git", "consumed_disk", | |
| ), | |
| resource.TestCheckResourceAttrPair( | |
| "stackit_git.git", "flavor", | |
| "data.stackit_git.git", "flavor", | |
| ), |
| @@ -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.
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
| stringplanmodifier.RequiresReplace(), | ||
| }, | ||
| Validators: []validator.String{ | ||
| stringvalidator.OneOf("eu01"), // Currently Intake supports only EU01 region |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if runnerResp.Id != nil && *runnerResp.Id == "" { | |
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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() { |
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.
same here
| payload.MaxMessageSizeKiB = conversion.Int64ValueToPointer(model.MaxMessageSizeKiB) | ||
| } | ||
|
|
||
| if !model.MaxMessagesPerHour.IsUnknown() { |
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.
same here
| if !model.Labels.IsUnknown() { | ||
| if model.Labels.IsNull() { | ||
| labels = map[string]string{} | ||
| payload.Labels = &labels |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it still exists, delete it 😉
| err := client.DeleteInstance(ctx, testutil.ProjectId, *gitInstances[i].Id).Execute() |
| var err error | ||
| if testutil.IntakeCustomEndpoint == "" { | ||
| client, err = intake.NewAPIClient( | ||
| sdkConfig.WithRegion("eu01"), |
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.
| 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 😅
# Conflicts: # go.mod # go.sum # stackit/internal/testutil/testutil.go # stackit/provider.go
89b2fc8 to
540b360
Compare
Co-authored-by: Ruben Hönle <git@hoenle.xyz>
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)