Skip to content

Commit cf8d535

Browse files
authored
fix(cvm): [125535953] tencentcloud_instance support user_data_replace_on_change (#3432)
* add * add
1 parent 3ec30de commit cf8d535

File tree

10 files changed

+318
-4
lines changed

10 files changed

+318
-4
lines changed

.changelog/3432.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_instance: support `user_data_replace_on_change`
3+
```

tencentcloud/services/cvm/resource_tc_instance.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
svctag "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/tag"
1919
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/vpc"
2020

21+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
2122
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
2223
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2324
cbs "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs/v20170312"
@@ -402,14 +403,20 @@ func ResourceTencentCloudInstance() *schema.Resource {
402403
Optional: true,
403404
Computed: true,
404405
ConflictsWith: []string{"user_data_raw"},
405-
Description: "The user data to be injected into this instance. Must be base64 encoded and up to 16 KB.",
406+
Description: "The user data to be injected into this instance. Must be base64 encoded and up to 16 KB. If `user_data_replace_on_change` is set to `true`, updates to this field will trigger the destruction and recreation of the CVM instance.",
406407
},
407408
"user_data_raw": {
408409
Type: schema.TypeString,
409410
Optional: true,
410411
Computed: true,
411412
ConflictsWith: []string{"user_data"},
412-
Description: "The user data to be injected into this instance, in plain text. Conflicts with `user_data`. Up to 16 KB after base64 encoded.",
413+
Description: "The user data to be injected into this instance, in plain text. Conflicts with `user_data`. Up to 16 KB after base64 encoded. If `user_data_replace_on_change` is set to `true`, updates to this field will trigger the destruction and recreation of the CVM instance.",
414+
},
415+
"user_data_replace_on_change": {
416+
Type: schema.TypeBool,
417+
Optional: true,
418+
Default: false,
419+
Description: "When used in combination with `user_data` or `user_data_raw` will trigger a destroy and recreate of the CVM instance when set to `true`. Default is `false`.",
413420
},
414421
"tags": {
415422
Type: schema.TypeMap,
@@ -498,6 +505,16 @@ func ResourceTencentCloudInstance() *schema.Resource {
498505
Description: "Instance os name.",
499506
},
500507
},
508+
509+
CustomizeDiff: customdiff.All(
510+
customdiff.ForceNewIf("user_data", func(_ context.Context, diff *schema.ResourceDiff, meta interface{}) bool {
511+
return diff.Get("user_data_replace_on_change").(bool)
512+
}),
513+
514+
customdiff.ForceNewIf("user_data_raw", func(_ context.Context, diff *schema.ResourceDiff, meta interface{}) bool {
515+
return diff.Get("user_data_replace_on_change").(bool)
516+
}),
517+
),
501518
}
502519
}
503520

vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff/compose.go

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff/computed.go

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff/condition.go

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff/doc.go

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff/force_new.go

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff/validate.go

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ github.com/hashicorp/terraform-plugin-sdk/terraform
708708
## explicit; go 1.17
709709
github.com/hashicorp/terraform-plugin-sdk/v2/diag
710710
github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest
711+
github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff
711712
github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging
712713
github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource
713714
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema

website/docs/r/instance.html.markdown

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,9 @@ The following arguments are supported:
304304
* `system_disk_size` - (Optional, Int) Size of the system disk. unit is GB, Default is 50GB. If modified, the instance may force stop.
305305
* `system_disk_type` - (Optional, String) System disk type. For more information on limits of system disk types, see [Storage Overview](https://intl.cloud.tencent.com/document/product/213/4952). Valid values: `LOCAL_BASIC`: local disk, `LOCAL_SSD`: local SSD disk, `CLOUD_BASIC`: cloud disk, `CLOUD_SSD`: cloud SSD disk, `CLOUD_PREMIUM`: Premium Cloud Storage, `CLOUD_BSSD`: Basic SSD, `CLOUD_HSSD`: Enhanced SSD, `CLOUD_TSSD`: Tremendous SSD. NOTE: If modified, the instance may force stop.
306306
* `tags` - (Optional, Map) A mapping of tags to assign to the resource. For tag limits, please refer to [Use Limits](https://intl.cloud.tencent.com/document/product/651/13354).
307-
* `user_data_raw` - (Optional, String) The user data to be injected into this instance, in plain text. Conflicts with `user_data`. Up to 16 KB after base64 encoded.
308-
* `user_data` - (Optional, String) The user data to be injected into this instance. Must be base64 encoded and up to 16 KB.
307+
* `user_data_raw` - (Optional, String) The user data to be injected into this instance, in plain text. Conflicts with `user_data`. Up to 16 KB after base64 encoded. If `user_data_replace_on_change` is set to `true`, updates to this field will trigger the destruction and recreation of the CVM instance.
308+
* `user_data_replace_on_change` - (Optional, Bool) When used in combination with `user_data` or `user_data_raw` will trigger a destroy and recreate of the CVM instance when set to `true`. Default is `false`.
309+
* `user_data` - (Optional, String) The user data to be injected into this instance. Must be base64 encoded and up to 16 KB. If `user_data_replace_on_change` is set to `true`, updates to this field will trigger the destruction and recreation of the CVM instance.
309310
* `vpc_id` - (Optional, String) The ID of a VPC network. If you want to create instances in a VPC network, this parameter must be set.
310311

311312
The `data_disks` object supports the following:

0 commit comments

Comments
 (0)