|
9 | 9 | "github.com/hashicorp/terraform-plugin-framework/types" |
10 | 10 | "github.com/scaleway/scaleway-sdk-go/api/cockpit/v1" |
11 | 11 | "github.com/scaleway/scaleway-sdk-go/scw" |
| 12 | + "github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional" |
12 | 13 | "github.com/scaleway/terraform-provider-scaleway/v2/internal/meta" |
13 | 14 | ) |
14 | 15 |
|
@@ -62,10 +63,7 @@ func (a *TriggerTestAlertAction) Schema(ctx context.Context, req action.SchemaRe |
62 | 63 | Required: true, |
63 | 64 | Description: "ID of the Project", |
64 | 65 | }, |
65 | | - "region": schema.StringAttribute{ |
66 | | - Optional: true, |
67 | | - Description: "Region to target. If not provided, will use the default region from the provider configuration", |
68 | | - }, |
| 66 | + "region": regional.SchemaAttribute(), |
69 | 67 | }, |
70 | 68 | } |
71 | 69 | } |
@@ -99,8 +97,19 @@ func (a *TriggerTestAlertAction) Invoke(ctx context.Context, req action.InvokeRe |
99 | 97 | } |
100 | 98 |
|
101 | 99 | var region scw.Region |
| 100 | + |
102 | 101 | if !data.Region.IsNull() && data.Region.ValueString() != "" { |
103 | | - region = scw.Region(data.Region.ValueString()) |
| 102 | + parsedRegion, err := scw.ParseRegion(data.Region.ValueString()) |
| 103 | + if err != nil { |
| 104 | + resp.Diagnostics.AddError( |
| 105 | + "Invalid region", |
| 106 | + fmt.Sprintf("The region attribute must be a valid Scaleway region. Got %q: %s", data.Region.ValueString(), err), |
| 107 | + ) |
| 108 | + |
| 109 | + return |
| 110 | + } |
| 111 | + |
| 112 | + region = parsedRegion |
104 | 113 | } else { |
105 | 114 | // Use default region from provider configuration |
106 | 115 | defaultRegion, exists := a.meta.ScwClient().GetDefaultRegion() |
|
0 commit comments