Skip to content

Commit 0926d92

Browse files
authored
Merge branch 'master' into bump_manual/gopkg.in/dnaeon/go-vcr.v4-4.0.6
2 parents aaf7cb4 + 2387a5d commit 0926d92

File tree

8 files changed

+1290
-27
lines changed

8 files changed

+1290
-27
lines changed

go.mod

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ require (
77
github.com/aws/aws-sdk-go-v2 v1.40.1
88
github.com/aws/aws-sdk-go-v2/config v1.31.13
99
github.com/aws/aws-sdk-go-v2/credentials v1.18.20
10-
github.com/aws/aws-sdk-go-v2/service/s3 v1.88.5
10+
github.com/aws/aws-sdk-go-v2/service/s3 v1.93.0
1111
github.com/aws/aws-sdk-go-v2/service/sns v1.39.8
12-
github.com/aws/aws-sdk-go-v2/service/sqs v1.42.12
12+
github.com/aws/aws-sdk-go-v2/service/sqs v1.42.18
1313
github.com/aws/smithy-go v1.24.0
1414
github.com/docker/docker v28.4.0+incompatible
1515
github.com/dustin/go-humanize v1.0.1
@@ -27,7 +27,7 @@ require (
2727
github.com/hashicorp/terraform-plugin-log v0.10.0
2828
github.com/hashicorp/terraform-plugin-mux v0.21.0
2929
github.com/hashicorp/terraform-plugin-sdk/v2 v2.38.1
30-
github.com/hashicorp/terraform-plugin-testing v1.13.3
30+
github.com/hashicorp/terraform-plugin-testing v1.14.0
3131
github.com/nats-io/jwt/v2 v2.8.0
3232
github.com/nats-io/nats.go v1.47.0
3333
github.com/robfig/cron/v3 v3.0.1
@@ -53,16 +53,16 @@ require (
5353
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
5454
github.com/armon/go-radix v1.0.0 // indirect
5555
github.com/aws/aws-sdk-go v1.55.5 // indirect
56-
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.2 // indirect
56+
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4 // indirect
5757
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.12 // indirect
5858
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.15 // indirect
5959
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.15 // indirect
6060
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect
61-
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.10 // indirect
62-
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.2 // indirect
63-
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.1 // indirect
64-
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.12 // indirect
65-
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.10 // indirect
61+
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.15 // indirect
62+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.4 // indirect
63+
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.6 // indirect
64+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.15 // indirect
65+
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.15 // indirect
6666
github.com/aws/aws-sdk-go-v2/service/sso v1.30.0 // indirect
6767
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.4 // indirect
6868
github.com/aws/aws-sdk-go-v2/service/sts v1.39.0 // indirect

go.sum

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU
7373
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
7474
github.com/aws/aws-sdk-go-v2 v1.40.1 h1:difXb4maDZkRH0x//Qkwcfpdg1XQVXEAEs2DdXldFFc=
7575
github.com/aws/aws-sdk-go-v2 v1.40.1/go.mod h1:MayyLB8y+buD9hZqkCW3kX1AKq07Y5pXxtgB+rRFhz0=
76-
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.2 h1:t9yYsydLYNBk9cJ73rgPhPWqOh/52fcWDQB5b1JsKSY=
77-
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.2/go.mod h1:IusfVNTmiSN3t4rhxWFaBAqn+mcNdwKtPcV16eYdgko=
76+
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4 h1:489krEF9xIGkOaaX3CE/Be2uWjiXrkCH6gUX+bZA/BU=
77+
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4/go.mod h1:IOAPF6oT9KCsceNTvvYMNHy0+kMF8akOjeDvPENWxp4=
7878
github.com/aws/aws-sdk-go-v2/config v1.31.13 h1:wcqQB3B0PgRPUF5ZE/QL1JVOyB0mbPevHFoAMpemR9k=
7979
github.com/aws/aws-sdk-go-v2/config v1.31.13/go.mod h1:ySB5D5ybwqGbT6c3GszZ+u+3KvrlYCUQNo62+hkKOFk=
8080
github.com/aws/aws-sdk-go-v2/credentials v1.18.20 h1:KFndAnHd9NUuzikHjQ8D5CfFVO+bgELkmcGY8yAw98Q=
@@ -87,22 +87,22 @@ github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.15 h1:AvltKnW9ewxX2hFmQS
8787
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.15/go.mod h1:3I4oCdZdmgrREhU74qS1dK9yZ62yumob+58AbFR4cQA=
8888
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 h1:WKuaxf++XKWlHWu9ECbMlha8WOEGm0OUEZqm4K/Gcfk=
8989
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4/go.mod h1:ZWy7j6v1vWGmPReu0iSGvRiise4YI5SkR3OHKTZ6Wuc=
90-
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.10 h1:FHw90xCTsofzk6vjU808TSuDtDfOOKPNdz5Weyc3tUI=
91-
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.10/go.mod h1:n8jdIE/8F3UYkg8O4IGkQpn2qUmapg/1K1yl29/uf/c=
92-
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.2 h1:xtuxji5CS0JknaXoACOunXOYOQzgfTvGAc9s2QdCJA4=
93-
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.2/go.mod h1:zxwi0DIR0rcRcgdbl7E2MSOvxDyyXGBlScvBkARFaLQ=
94-
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.1 h1:ne+eepnDB2Wh5lHKzELgEncIqeVlQ1rSF9fEa4r5I+A=
95-
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.1/go.mod h1:u0Jkg0L+dcG1ozUq21uFElmpbmjBnhHR5DELHIme4wg=
96-
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.12 h1:MM8imH7NZ0ovIVX7D2RxfMDv7Jt9OiUXkcQ+GqywA7M=
97-
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.12/go.mod h1:gf4OGwdNkbEsb7elw2Sy76odfhwNktWII3WgvQgQQ6w=
98-
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.10 h1:DA+Hl5adieRyFvE7pCvBWm3VOZTRexGVkXw33SUqNoY=
99-
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.10/go.mod h1:L+A89dH3/gr8L4ecrdzuXUYd1znoko6myzndVGZx/DA=
100-
github.com/aws/aws-sdk-go-v2/service/s3 v1.88.5 h1:FlGScxzCGNzT+2AvHT1ZGMvxTwAMa6gsooFb1pO/AiM=
101-
github.com/aws/aws-sdk-go-v2/service/s3 v1.88.5/go.mod h1:N/iojY+8bW3MYol9NUMuKimpSbPEur75cuI1SmtonFM=
90+
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.15 h1:NLYTEyZmVZo0Qh183sC8nC+ydJXOOeIL/qI/sS3PdLY=
91+
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.15/go.mod h1:Z803iB3B0bc8oJV8zH2PERLRfQUJ2n2BXISpsA4+O1M=
92+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.4 h1:0ryTNEdJbzUCEWkVXEXoqlXV72J5keC1GvILMOuD00E=
93+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.4/go.mod h1:HQ4qwNZh32C3CBeO6iJLQlgtMzqeG17ziAA/3KDJFow=
94+
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.6 h1:P1MU/SuhadGvg2jtviDXPEejU3jBNhoeeAlRadHzvHI=
95+
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.6/go.mod h1:5KYaMG6wmVKMFBSfWoyG/zH8pWwzQFnKgpoSRlXHKdQ=
96+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.15 h1:3/u/4yZOffg5jdNk1sDpOQ4Y+R6Xbh+GzpDrSZjuy3U=
97+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.15/go.mod h1:4Zkjq0FKjE78NKjabuM4tRXKFzUJWXgP0ItEZK8l7JU=
98+
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.15 h1:wsSQ4SVz5YE1crz0Ap7VBZrV4nNqZt4CIBBT8mnwoNc=
99+
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.15/go.mod h1:I7sditnFGtYMIqPRU1QoHZAUrXkGp4SczmlLwrNPlD0=
100+
github.com/aws/aws-sdk-go-v2/service/s3 v1.93.0 h1:IrbE3B8O9pm3lsg96AXIN5MXX4pECEuExh/A0Du3AuI=
101+
github.com/aws/aws-sdk-go-v2/service/s3 v1.93.0/go.mod h1:/sJLzHtiiZvs6C1RbxS/anSAFwZD6oC6M/kotQzOiLw=
102102
github.com/aws/aws-sdk-go-v2/service/sns v1.39.8 h1:s2QY81HBbJ+zbafTcWQmMaHj0C18VoJON/gDY1ibrEg=
103103
github.com/aws/aws-sdk-go-v2/service/sns v1.39.8/go.mod h1:3aOzyhwa/mXPZYLwGaALfl88GFRXHQKXdyQSq2L/Y4g=
104-
github.com/aws/aws-sdk-go-v2/service/sqs v1.42.12 h1:gKm7A7ShrL5Pn53ec5GqzQB2tWvk978bbasFEZfwu2U=
105-
github.com/aws/aws-sdk-go-v2/service/sqs v1.42.12/go.mod h1:tQRO8Q9JzfImAG5sG3TUyeF/EqCXwvZ7TA8gz5Whpec=
104+
github.com/aws/aws-sdk-go-v2/service/sqs v1.42.18 h1:zHL8HTKRbiJ2UfQdjeszQtPp9cHFeuwZqFB5/C02FGs=
105+
github.com/aws/aws-sdk-go-v2/service/sqs v1.42.18/go.mod h1:Ii4ZZhKuXo8+is8A+9AZo2vXeCfFJyR+pXHUromSz+U=
106106
github.com/aws/aws-sdk-go-v2/service/sso v1.30.0 h1:xHXvxst78wBpJFgDW07xllOx0IAzbryrSdM4nMVQ4Dw=
107107
github.com/aws/aws-sdk-go-v2/service/sso v1.30.0/go.mod h1:/e8m+AO6HNPPqMyfKRtzZ9+mBF5/x1Wk8QiDva4m07I=
108108
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.4 h1:tBw2Qhf0kj4ZwtsVpDiVRU3zKLvjvjgIjHMKirxXg8M=
@@ -336,8 +336,8 @@ github.com/hashicorp/terraform-plugin-mux v0.21.0 h1:QsEYnzSD2c3zT8zUrUGqaFGhV/Z
336336
github.com/hashicorp/terraform-plugin-mux v0.21.0/go.mod h1:Qpt8+6AD7NmL0DS7ASkN0EXpDQ2J/FnnIgeUr1tzr5A=
337337
github.com/hashicorp/terraform-plugin-sdk/v2 v2.38.1 h1:mlAq/OrMlg04IuJT7NpefI1wwtdpWudnEmjuQs04t/4=
338338
github.com/hashicorp/terraform-plugin-sdk/v2 v2.38.1/go.mod h1:GQhpKVvvuwzD79e8/NZ+xzj+ZpWovdPAe8nfV/skwNU=
339-
github.com/hashicorp/terraform-plugin-testing v1.13.3 h1:QLi/khB8Z0a5L54AfPrHukFpnwsGL8cwwswj4RZduCo=
340-
github.com/hashicorp/terraform-plugin-testing v1.13.3/go.mod h1:WHQ9FDdiLoneey2/QHpGM/6SAYf4A7AZazVg7230pLE=
339+
github.com/hashicorp/terraform-plugin-testing v1.14.0 h1:5t4VKrjOJ0rg0sVuSJ86dz5K7PHsMO6OKrHFzDBerWA=
340+
github.com/hashicorp/terraform-plugin-testing v1.14.0/go.mod h1:1qfWkecyYe1Do2EEOK/5/WnTyvC8wQucUkkhiGLg5nk=
341341
github.com/hashicorp/terraform-registry-address v0.4.0 h1:S1yCGomj30Sao4l5BMPjTGZmCNzuv7/GDTDX99E9gTk=
342342
github.com/hashicorp/terraform-registry-address v0.4.0/go.mod h1:LRS1Ay0+mAiRkUyltGT+UHWkIqTFvigGn/LbMshfflE=
343343
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
package jobs
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
8+
"github.com/hashicorp/terraform-plugin-framework/action"
9+
"github.com/hashicorp/terraform-plugin-framework/action/schema"
10+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
11+
"github.com/hashicorp/terraform-plugin-framework/types"
12+
jobs "github.com/scaleway/scaleway-sdk-go/api/jobs/v1alpha1"
13+
"github.com/scaleway/scaleway-sdk-go/scw"
14+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality"
15+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
16+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
17+
)
18+
19+
var (
20+
_ action.Action = (*StartJobDefinitionAction)(nil)
21+
_ action.ActionWithConfigure = (*StartJobDefinitionAction)(nil)
22+
)
23+
24+
type StartJobDefinitionAction struct {
25+
jobsAPI *jobs.API
26+
meta *meta.Meta
27+
}
28+
29+
func (a *StartJobDefinitionAction) Configure(ctx context.Context, req action.ConfigureRequest, resp *action.ConfigureResponse) {
30+
if req.ProviderData == nil {
31+
return
32+
}
33+
34+
m, ok := req.ProviderData.(*meta.Meta)
35+
if !ok {
36+
resp.Diagnostics.AddError(
37+
"Unexpected Action Configure Type",
38+
fmt.Sprintf("Expected *meta.Meta, got: %T. Please report this issue to the provider developers.", req.ProviderData),
39+
)
40+
41+
return
42+
}
43+
44+
client := m.ScwClient()
45+
a.jobsAPI = jobs.NewAPI(client)
46+
a.meta = m
47+
}
48+
49+
func (a *StartJobDefinitionAction) Metadata(ctx context.Context, req action.MetadataRequest, resp *action.MetadataResponse) {
50+
resp.TypeName = req.ProviderTypeName + "_job_definition_start_action"
51+
}
52+
53+
type StartJobDefinitionActionModel struct {
54+
JobDefinitionID types.String `tfsdk:"job_definition_id"`
55+
Region types.String `tfsdk:"region"`
56+
Command types.String `tfsdk:"command"`
57+
EnvironmentVariables types.Map `tfsdk:"environment_variables"`
58+
Replicas types.Int64 `tfsdk:"replicas"`
59+
}
60+
61+
func NewStartJobDefinitionAction() action.Action {
62+
return &StartJobDefinitionAction{}
63+
}
64+
65+
func (a *StartJobDefinitionAction) Schema(ctx context.Context, req action.SchemaRequest, resp *action.SchemaResponse) {
66+
resp.Schema = schema.Schema{
67+
Attributes: map[string]schema.Attribute{
68+
"job_definition_id": schema.StringAttribute{
69+
Required: true,
70+
Description: "ID of the job definition to start. Can be a plain UUID or a regional ID.",
71+
Validators: []validator.String{
72+
stringvalidator.LengthAtLeast(1),
73+
},
74+
},
75+
"region": schema.StringAttribute{
76+
Optional: true,
77+
Description: "Region of the job definition. If not set, the region is derived from the job_definition_id when possible or from the provider configuration.",
78+
},
79+
"command": schema.StringAttribute{
80+
Optional: true,
81+
Description: "Contextual startup command for this specific job run.",
82+
},
83+
"environment_variables": schema.MapAttribute{
84+
Optional: true,
85+
ElementType: types.StringType,
86+
Description: "Contextual environment variables for this specific job run.",
87+
},
88+
"replicas": schema.Int64Attribute{
89+
Optional: true,
90+
Description: "Number of jobs to run.",
91+
},
92+
},
93+
}
94+
}
95+
96+
func (a *StartJobDefinitionAction) Invoke(ctx context.Context, req action.InvokeRequest, resp *action.InvokeResponse) {
97+
var data StartJobDefinitionActionModel
98+
99+
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
100+
101+
if resp.Diagnostics.HasError() {
102+
return
103+
}
104+
105+
if a.jobsAPI == nil {
106+
resp.Diagnostics.AddError(
107+
"Unconfigured jobsAPI",
108+
"The action was not properly configured. The Scaleway client is missing. "+
109+
"This is usually a bug in the provider. Please report it to the maintainers.",
110+
)
111+
112+
return
113+
}
114+
115+
if data.JobDefinitionID.IsNull() || data.JobDefinitionID.ValueString() == "" {
116+
resp.Diagnostics.AddError(
117+
"Missing job_definition_id",
118+
"The job_definition_id attribute is required to start a job definition.",
119+
)
120+
121+
return
122+
}
123+
124+
jobDefinitionID := locality.ExpandID(data.JobDefinitionID.ValueString())
125+
126+
var (
127+
region scw.Region
128+
err error
129+
)
130+
131+
if !data.Region.IsNull() && data.Region.ValueString() != "" {
132+
region = scw.Region(data.Region.ValueString())
133+
} else {
134+
// Try to derive region from the job_definition_id if it is a regional ID.
135+
if derivedRegion, id, parseErr := regional.ParseID(data.JobDefinitionID.ValueString()); parseErr == nil {
136+
region = derivedRegion
137+
jobDefinitionID = id
138+
} else {
139+
// Use default region from provider configuration
140+
defaultRegion, exists := a.meta.ScwClient().GetDefaultRegion()
141+
if !exists {
142+
resp.Diagnostics.AddError(
143+
"Missing region",
144+
"The region attribute is required to start a job definition. Please provide it explicitly or configure a default region in the provider.",
145+
)
146+
147+
return
148+
}
149+
150+
region = defaultRegion
151+
}
152+
}
153+
154+
startReq := &jobs.StartJobDefinitionRequest{
155+
Region: region,
156+
JobDefinitionID: jobDefinitionID,
157+
}
158+
159+
if !data.Command.IsNull() && data.Command.ValueString() != "" {
160+
command := data.Command.ValueString()
161+
startReq.Command = &command
162+
}
163+
164+
if !data.EnvironmentVariables.IsNull() {
165+
envVars := make(map[string]string)
166+
resp.Diagnostics.Append(data.EnvironmentVariables.ElementsAs(ctx, &envVars, false)...)
167+
168+
if resp.Diagnostics.HasError() {
169+
return
170+
}
171+
172+
if len(envVars) > 0 {
173+
startReq.EnvironmentVariables = &envVars
174+
}
175+
}
176+
177+
if !data.Replicas.IsNull() {
178+
replicas := uint32(data.Replicas.ValueInt64())
179+
startReq.Replicas = &replicas
180+
}
181+
182+
_, err = a.jobsAPI.StartJobDefinition(startReq, scw.WithContext(ctx))
183+
if err != nil {
184+
resp.Diagnostics.AddError(
185+
"Error executing Jobs StartJobDefinition action",
186+
fmt.Sprintf("Failed to start job definition %s: %s", jobDefinitionID, err),
187+
)
188+
189+
return
190+
}
191+
}

0 commit comments

Comments
 (0)