Skip to content

Commit 03896c1

Browse files
authored
Merge pull request #754 from ovh/dev/aamstutz/fix-order-attributes
fix: Stop reading order-related information in resources to fix wrong imports
2 parents 856f2de + a32c98a commit 03896c1

File tree

357 files changed

+13065
-5551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

357 files changed

+13065
-5551
lines changed

go.mod

+12-10
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ require (
55
github.com/hashicorp/go-cleanhttp v0.5.2
66
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
77
github.com/hashicorp/go-version v1.7.0
8-
github.com/hashicorp/terraform-plugin-framework v1.7.0
8+
github.com/hashicorp/terraform-plugin-framework v1.12.0
99
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
10-
github.com/hashicorp/terraform-plugin-go v0.23.0
10+
github.com/hashicorp/terraform-plugin-go v0.24.0
1111
github.com/hashicorp/terraform-plugin-log v0.9.0
12-
github.com/hashicorp/terraform-plugin-mux v0.15.0
12+
github.com/hashicorp/terraform-plugin-mux v0.16.0
1313
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
1414
github.com/hashicorp/terraform-plugin-testing v1.10.0
1515
github.com/ovh/go-ovh v1.6.0
@@ -29,7 +29,7 @@ require (
2929
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
3030
github.com/hashicorp/go-hclog v1.6.3 // indirect
3131
github.com/hashicorp/go-multierror v1.1.1 // indirect
32-
github.com/hashicorp/go-plugin v1.6.0 // indirect
32+
github.com/hashicorp/go-plugin v1.6.1 // indirect
3333
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
3434
github.com/hashicorp/go-uuid v1.0.3 // indirect
3535
github.com/hashicorp/hc-install v0.8.0 // indirect
@@ -55,19 +55,21 @@ require (
5555
github.com/zclconf/go-cty v1.15.0 // indirect
5656
golang.org/x/crypto v0.26.0 // indirect
5757
golang.org/x/mod v0.19.0 // indirect
58-
golang.org/x/net v0.25.0 // indirect
59-
golang.org/x/oauth2 v0.18.0 // indirect
58+
golang.org/x/net v0.26.0 // indirect
59+
golang.org/x/oauth2 v0.21.0 // indirect
6060
golang.org/x/sync v0.8.0 // indirect
6161
golang.org/x/sys v0.23.0 // indirect
6262
golang.org/x/text v0.17.0 // indirect
6363
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
6464
google.golang.org/appengine v1.6.8 // indirect
65-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
66-
google.golang.org/grpc v1.63.2 // indirect
67-
google.golang.org/protobuf v1.34.0 // indirect
65+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect
66+
google.golang.org/grpc v1.66.2 // indirect
67+
google.golang.org/protobuf v1.34.2 // indirect
6868
gopkg.in/ini.v1 v1.67.0 // indirect
6969
)
7070

71-
go 1.21
71+
go 1.22.0
72+
73+
toolchain go1.22.8
7274

7375
retract v0.36.0 // OVH_ENDPOINT environment variable prevent a correct usage of the terraform provider

go.sum

+28-72
Large diffs are not rendered by default.

ovh/order.go

+19-8
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
)
2121

2222
var (
23-
reTerminateEmailToken = regexp.MustCompile(`.*https://www.ovh.com/manager/#/billing/confirmTerminate\?id=[[:alnum:]]+&token=([[:alnum:]]+).*`)
24-
terminateEmailMatch = "https://www.ovh.com/manager/#/billing/confirmTerminate"
23+
reTerminateEmailToken = regexp.MustCompile(`.*/billing/confirmTerminate\?id=[[:alnum:]]+&token=([[:alnum:]]+).*`)
24+
terminateEmailMatch = "/billing/confirmTerminate"
2525
)
2626

2727
func genericOrderSchema(withOptions bool) map[string]*schema.Schema {
@@ -32,9 +32,11 @@ func genericOrderSchema(withOptions bool) map[string]*schema.Schema {
3232

3333
orderSchema := map[string]*schema.Schema{
3434
"ovh_subsidiary": {
35-
Type: schema.TypeString,
36-
Required: true,
37-
ForceNew: true,
35+
Type: schema.TypeString,
36+
ForceNew: true,
37+
Optional: true,
38+
Computed: true,
39+
3840
Description: "Ovh Subsidiary",
3941
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
4042
err := helpers.ValidateSubsidiary(v.(string))
@@ -64,9 +66,11 @@ func genericOrderSchema(withOptions bool) map[string]*schema.Schema {
6466
},
6567

6668
"plan": {
67-
Type: schema.TypeList,
68-
Required: true,
69-
ForceNew: true,
69+
Type: schema.TypeList,
70+
ForceNew: true,
71+
Optional: true,
72+
Computed: true,
73+
7074
Description: "Product Plan to order",
7175
MaxItems: 1,
7276
Elem: &schema.Resource{
@@ -239,6 +243,13 @@ func orderCreateFromResource(d *schema.ResourceData, meta interface{}, product s
239243
}
240244

241245
func orderCreate(d *OrderModel, config *Config, product string, waitForCompletion bool) error {
246+
if d.OvhSubsidiary.ValueString() == "" {
247+
return fmt.Errorf("ovh_subsidiary is missing from configuration")
248+
}
249+
if len(d.Plan.Elements()) == 0 {
250+
return fmt.Errorf("plan is missing from configuration")
251+
}
252+
242253
// create Cart
243254
cartParams := &OrderCartCreateOpts{
244255
OvhSubsidiary: strings.ToUpper(d.OvhSubsidiary.ValueString()),

ovh/order_resource_gen.go

+9-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ovh/resource_cloud_project.go

+4-21
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func resourceCloudProjectSchema() map[string]*schema.Schema {
7272

7373
func resourceCloudProjectCreate(d *schema.ResourceData, meta interface{}) error {
7474
if err := orderCreateFromResource(d, meta, "cloud", true); err != nil {
75-
return fmt.Errorf("Could not order cloud project: %q", err)
75+
return fmt.Errorf("could not order cloud project: %q", err)
7676
}
7777

7878
return resourceCloudProjectUpdate(d, meta)
@@ -92,7 +92,7 @@ func resourceCloudProjectGetServiceName(config *Config, order *MeOrder, details
9292
for _, orderDetail := range details {
9393
operations, err := orderDetailOperations(config.OVHClient, order.OrderId, orderDetail.OrderDetailId)
9494
if err != nil {
95-
return "", fmt.Errorf("Could not read cloudProject order details operations: %q", err)
95+
return "", fmt.Errorf("could not read cloudProject order details operations: %q", err)
9696
}
9797
for _, operation := range operations {
9898
if publicCloudProjectNameFormatRegex.MatchString(operation.Resource.Name) {
@@ -101,13 +101,13 @@ func resourceCloudProjectGetServiceName(config *Config, order *MeOrder, details
101101
}
102102
}
103103

104-
return "", fmt.Errorf("Unknown service name")
104+
return "", fmt.Errorf("unknown service name")
105105
}
106106

107107
func resourceCloudProjectUpdate(d *schema.ResourceData, meta interface{}) error {
108108
order, details, err := orderReadInResource(d, meta)
109109
if err != nil {
110-
return fmt.Errorf("Could not read cloud project order: %q", err)
110+
return fmt.Errorf("could not read cloud project order: %q", err)
111111
}
112112

113113
config := meta.(*Config)
@@ -150,23 +150,6 @@ func resourceCloudProjectRead(d *schema.ResourceData, meta interface{}) error {
150150
d.Set(k, v)
151151
}
152152

153-
// Retrieve order information
154-
serviceObj, err := serviceFromServiceName(config.OVHClient, "cloud/project", serviceName)
155-
if err != nil {
156-
return fmt.Errorf("failed to retrieve cloud project details: %w", err)
157-
}
158-
if len(details) > 0 {
159-
serviceObj.OrderDetailExtension = details[0].Extension
160-
}
161-
d.Set("plan", serviceObj.ToSDKv2PlanValue())
162-
163-
// Retrieve subsidiary information
164-
var me MeResponse
165-
if err := config.OVHClient.Get("/me", &me); err != nil {
166-
return fmt.Errorf("error retrieving account information: %w", err)
167-
}
168-
d.Set("ovh_subsidiary", me.OvhSubsidiary)
169-
170153
return nil
171154
}
172155

ovh/resource_dedicated_server.go

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ func (d *dedicatedServerResource) Schema(ctx context.Context, req resource.Schem
5454
}
5555

5656
func (d *dedicatedServerResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
57+
// Here we force the attribute "plan" to an empty array because it won't be fetched by the Read function.
58+
// If we don't do this, Terraform always shows a diff on the following plans (null => []), due to the
59+
// plan modifier RequiresReplace that initializes the attribute to its zero-value (an empty array).
60+
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("plan"), ovhtypes.TfListNestedValue[PlanValue]{
61+
ListValue: basetypes.NewListValueMust(PlanValue{}.Type(ctx), make([]attr.Value, 0)),
62+
})...)
5763
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("service_name"), req.ID)...)
5864
}
5965

ovh/resource_domain_zone.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func resourceDomainZoneSchema() map[string]*schema.Schema {
7171

7272
func resourceDomainZoneCreate(d *schema.ResourceData, meta interface{}) error {
7373
if err := orderCreateFromResource(d, meta, "dns", true); err != nil {
74-
return fmt.Errorf("Could not order domain zone: %q", err)
74+
return fmt.Errorf("could not order domain zone: %q", err)
7575
}
7676

7777
return resourceDomainZoneRead(d, meta)
@@ -80,7 +80,7 @@ func resourceDomainZoneCreate(d *schema.ResourceData, meta interface{}) error {
8080
func resourceDomainZoneRead(d *schema.ResourceData, meta interface{}) error {
8181
_, details, err := orderReadInResource(d, meta)
8282
if err != nil {
83-
return fmt.Errorf("Could not read domainZone order: %q", err)
83+
return fmt.Errorf("could not read domainZone order: %q", err)
8484
}
8585

8686
config := meta.(*Config)
@@ -104,7 +104,7 @@ func resourceDomainZoneRead(d *schema.ResourceData, meta interface{}) error {
104104
func resourceDomainZoneDelete(d *schema.ResourceData, meta interface{}) error {
105105
_, details, err := orderReadInResource(d, meta)
106106
if err != nil {
107-
return fmt.Errorf("Could not read domainZone order: %q", err)
107+
return fmt.Errorf("could not read domainZone order: %q", err)
108108
}
109109

110110
config := meta.(*Config)

ovh/resource_domain_zone_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ func TestAccResourceDomainZone_basic(t *testing.T) {
145145
"ovh_domain_zone.zone", "urn"),
146146
),
147147
},
148+
{
149+
ResourceName: "ovh_domain_zone.zone",
150+
ImportState: true,
151+
ImportStateVerify: true,
152+
ImportStateVerifyIgnore: []string{"plan", "ovh_subsidiary"},
153+
},
148154
},
149155
})
150156
}

ovh/resource_hosting_privatedatabase_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ func TestAccHostingPrivateDatabase_basic(t *testing.T) {
158158
"ovh_hosting_privatedatabase.database", "urn"),
159159
),
160160
},
161+
{
162+
ResourceName: "ovh_hosting_privatedatabase.database",
163+
ImportState: true,
164+
ImportStateVerify: true,
165+
ImportStateVerifyIgnore: []string{"plan", "ovh_subsidiary"},
166+
},
161167
},
162168
})
163169
}

ovh/resource_ip_service.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ func resourceIpService() *schema.Resource {
2121
Delete: resourceIpServiceDelete,
2222

2323
Importer: &schema.ResourceImporter{
24-
State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
24+
State: func(d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) {
25+
d.Set("service_name", d.Id())
2526
return []*schema.ResourceData{d}, nil
2627
},
2728
},
@@ -107,14 +108,14 @@ func resourceIpServiceCreate(d *schema.ResourceData, meta interface{}) error {
107108
return fmt.Errorf("failed to get service name from order ID: %w", err)
108109
}
109110

111+
d.SetId(serviceName)
110112
d.Set("service_name", serviceName)
111113

112114
return resourceIpServiceUpdate(d, meta)
113115
}
114116

115117
func resourceIpServiceUpdate(d *schema.ResourceData, meta interface{}) error {
116118
config := meta.(*Config)
117-
118119
serviceName := d.Get("service_name").(string)
119120

120121
log.Printf("[DEBUG] Will update ip: %s", serviceName)
@@ -136,9 +137,7 @@ func resourceIpServiceRead(d *schema.ResourceData, meta interface{}) error {
136137
log.Printf("[DEBUG] Will read ip: %s", serviceName)
137138

138139
r := &IpService{}
139-
endpoint := fmt.Sprintf("/ip/service/%s",
140-
url.PathEscape(serviceName),
141-
)
140+
endpoint := fmt.Sprintf("/ip/service/%s", url.PathEscape(serviceName))
142141

143142
// This retry logic is there to handle a known API bug
144143
// which happens while an ipblock is attached/detached from
@@ -176,11 +175,10 @@ func resourceIpServiceRead(d *schema.ResourceData, meta interface{}) error {
176175

177176
func resourceIpServiceDelete(d *schema.ResourceData, meta interface{}) error {
178177
config := meta.(*Config)
179-
id := d.Id()
180178
serviceName := d.Get("service_name").(string)
181179

182180
terminate := func() (string, error) {
183-
log.Printf("[DEBUG] Will terminate ip %s for order %s", serviceName, id)
181+
log.Printf("[DEBUG] Will terminate ip %s", serviceName)
184182
endpoint := fmt.Sprintf(
185183
"/ip/service/%s/terminate",
186184
url.PathEscape(serviceName),
@@ -195,7 +193,7 @@ func resourceIpServiceDelete(d *schema.ResourceData, meta interface{}) error {
195193
}
196194

197195
confirmTerminate := func(token string) error {
198-
log.Printf("[DEBUG] Will confirm termination of ip %s for order %s", serviceName, id)
196+
log.Printf("[DEBUG] Will confirm termination of ip %s", serviceName)
199197
endpoint := fmt.Sprintf(
200198
"/ip/service/%s/confirmTermination",
201199
url.PathEscape(serviceName),

ovh/resource_ip_service_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ func TestAccResourceIpService_basic(t *testing.T) {
149149
"ovh_ip_service.ipblock", "description", desc),
150150
),
151151
},
152+
{
153+
ResourceName: "ovh_ip_service.ipblock",
154+
ImportState: true,
155+
ImportStateVerify: true,
156+
ImportStateVerifyIgnore: []string{"plan", "ovh_subsidiary"},
157+
},
152158
},
153159
})
154160
}

ovh/resource_iploadbalancing_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ func TestAccResourceIpLoadbalancing_basic(t *testing.T) {
180180
"ovh_iploadbalancing.iplb-lb1", "urn"),
181181
),
182182
},
183+
{
184+
ResourceName: "ovh_iploadbalancing.iplb-lb1",
185+
ImportState: true,
186+
ImportStateVerify: true,
187+
ImportStateVerifyIgnore: []string{"plan", "ovh_subsidiary"},
188+
},
183189
},
184190
})
185191
}

ovh/resource_okms.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,7 @@ func (r *okmsResource) Update(ctx context.Context, req resource.UpdateRequest, r
219219
data.Iam.DisplayName = planData.DisplayName
220220
err := r.waitKmsUpdate(ctx, data.Id.ValueString(), 1*time.Minute, func(responseData *OkmsModel) bool {
221221
// KMS name was updated successfully
222-
if responseData.DisplayName.ValueString() == data.DisplayName.ValueString() {
223-
return true
224-
}
225-
return false
222+
return responseData.DisplayName.ValueString() == data.DisplayName.ValueString()
226223
})
227224

228225
if err != nil {

0 commit comments

Comments
 (0)