diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index b8ba1d72e7..9c6b198a06 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -2447,6 +2447,10 @@ func Provider() *schema.Provider { "tencentcloud_cvm_renew_instance": resourceTencentCloudCvmRenewInstance(), "tencentcloud_cvm_export_images": resourceTencentCloudCvmExportImages(), "tencentcloud_cvm_image_share_permission": resourceTencentCloudCvmImageSharePermission(), + "tencentcloud_cvm_import_image": resourceTencentCloudCvmImportImage(), + "tencentcloud_cvm_renew_host": resourceTencentCloudCvmRenewHost(), + "tencentcloud_cvm_program_fpga_image": resourceTencentCloudCvmProgramFpgaImage(), + "tencentcloud_cvm_modify_instance_disk_type": resourceTencentCloudCvmModifyInstanceDiskType(), "tencentcloud_lighthouse_disk_backup": resourceTencentCloudLighthouseDiskBackup(), "tencentcloud_lighthouse_apply_disk_backup": resourceTencentCloudLighthouseApplyDiskBackup(), "tencentcloud_lighthouse_disk_attachment": resourceTencentCloudLighthouseDiskAttachment(), diff --git a/tencentcloud/resource_tc_cvm_import_image.go b/tencentcloud/resource_tc_cvm_import_image.go new file mode 100644 index 0000000000..a8189643d8 --- /dev/null +++ b/tencentcloud/resource_tc_cvm_import_image.go @@ -0,0 +1,274 @@ +/* +Provides a resource to create a cvm import_image + +Example Usage + +```hcl +resource "tencentcloud_cvm_import_image" "import_image" { + architecture = "x86_64" + os_type = "CentOS" + os_version = "7" + image_url = "" + image_name = "sample" + image_description = "sampleimage" + dry_run = false + force = false + tag_specification { + resource_type = "image" + tags { + key = "tagKey" + value = "tagValue" + } + + } + license_type = "TencentCloud" + boot_mode = "Legacy BIOS" + tags = { + "createdBy" = "terraform" + } +} +``` + +Import + +cvm import_image can be imported using the id, e.g. + +``` +terraform import tencentcloud_cvm_import_image.import_image import_image_id +``` +*/ +package tencentcloud + +import ( + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudCvmImportImage() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudCvmImportImageCreate, + Read: resourceTencentCloudCvmImportImageRead, + Delete: resourceTencentCloudCvmImportImageDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "architecture": { + Required: true, + ForceNew: true, + Type: schema.TypeString, + Description: "OS architecture of the image to be imported, `x86_64` or `i386`.", + }, + + "os_type": { + Required: true, + ForceNew: true, + Type: schema.TypeString, + Description: "OS type of the image to be imported. You can call `DescribeImportImageOs` to obtain the list of supported operating systems.", + }, + + "os_version": { + Required: true, + ForceNew: true, + Type: schema.TypeString, + Description: "OS version of the image to be imported. You can call `DescribeImportImageOs` to obtain the list of supported operating systems.", + }, + + "image_url": { + Required: true, + ForceNew: true, + Type: schema.TypeString, + Description: "Address on COS where the image to be imported is stored.", + }, + + "image_name": { + Required: true, + ForceNew: true, + Type: schema.TypeString, + Description: "Image name.", + }, + + "image_description": { + Optional: true, + ForceNew: true, + Type: schema.TypeString, + Description: "Image description.", + }, + + "dry_run": { + Optional: true, + ForceNew: true, + Type: schema.TypeBool, + Description: "Dry run to check the parameters without performing the operation.", + }, + + "force": { + Optional: true, + ForceNew: true, + Type: schema.TypeBool, + Description: "Whether to force import the image.", + }, + + "tag_specification": { + Optional: true, + ForceNew: true, + Type: schema.TypeList, + Description: "Tag description list. This parameter is used to bind a tag to a custom image.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "resource_type": { + Type: schema.TypeString, + Required: true, + Description: "Resource type. Valid values: instance (CVM), host (CDH), image (for image), and keypair (for key). Note: This field may return null, indicating that no valid values can be obtained.", + }, + "tags": { + Type: schema.TypeList, + Required: true, + Description: "Tag pairs Note: This field may return null, indicating that no valid values can be obtained.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "key": { + Type: schema.TypeString, + Required: true, + Description: "Tag key.", + }, + "value": { + Type: schema.TypeString, + Required: true, + Description: "Tag value.", + }, + }, + }, + }, + }, + }, + }, + + "license_type": { + Optional: true, + ForceNew: true, + Type: schema.TypeString, + Description: "The license type used to activate the OS after importing an image. Valid values: TencentCloud: Tencent Cloud official license BYOL: Bring Your Own License.", + }, + + "boot_mode": { + Optional: true, + ForceNew: true, + Type: schema.TypeString, + Description: "Boot mode.", + }, + }, + } +} + +func resourceTencentCloudCvmImportImageCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cvm_import_image.create")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + var ( + request = cvm.NewImportImageRequest() + imageUrl string + ) + if v, ok := d.GetOk("architecture"); ok { + request.Architecture = helper.String(v.(string)) + } + + if v, ok := d.GetOk("os_type"); ok { + request.OsType = helper.String(v.(string)) + } + + if v, ok := d.GetOk("os_version"); ok { + request.OsVersion = helper.String(v.(string)) + } + + if v, ok := d.GetOk("image_url"); ok { + imageUrl = v.(string) + request.ImageUrl = helper.String(imageUrl) + } + + if v, ok := d.GetOk("image_name"); ok { + request.ImageName = helper.String(v.(string)) + } + + if v, ok := d.GetOk("image_description"); ok { + request.ImageDescription = helper.String(v.(string)) + } + + if v, _ := d.GetOk("dry_run"); v != nil { + request.DryRun = helper.Bool(v.(bool)) + } + + if v, _ := d.GetOk("force"); v != nil { + request.Force = helper.Bool(v.(bool)) + } + + if v, ok := d.GetOk("tag_specification"); ok { + for _, item := range v.([]interface{}) { + dMap := item.(map[string]interface{}) + tagSpecification := cvm.TagSpecification{} + if v, ok := dMap["resource_type"]; ok { + tagSpecification.ResourceType = helper.String(v.(string)) + } + if v, ok := dMap["tags"]; ok { + for _, item := range v.([]interface{}) { + tagsMap := item.(map[string]interface{}) + tag := cvm.Tag{} + if v, ok := tagsMap["key"]; ok { + tag.Key = helper.String(v.(string)) + } + if v, ok := tagsMap["value"]; ok { + tag.Value = helper.String(v.(string)) + } + tagSpecification.Tags = append(tagSpecification.Tags, &tag) + } + } + request.TagSpecification = append(request.TagSpecification, &tagSpecification) + } + } + + if v, ok := d.GetOk("license_type"); ok { + request.LicenseType = helper.String(v.(string)) + } + + if v, ok := d.GetOk("boot_mode"); ok { + request.BootMode = helper.String(v.(string)) + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseCvmClient().ImportImage(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + if err != nil { + log.Printf("[CRITAL]%s operate cvm importImage failed, reason:%+v", logId, err) + return err + } + + d.SetId(imageUrl) + + return resourceTencentCloudCvmImportImageRead(d, meta) +} + +func resourceTencentCloudCvmImportImageRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cvm_import_image.read")() + defer inconsistentCheck(d, meta)() + + return nil +} + +func resourceTencentCloudCvmImportImageDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cvm_import_image.delete")() + defer inconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/resource_tc_cvm_import_image_test.go b/tencentcloud/resource_tc_cvm_import_image_test.go new file mode 100644 index 0000000000..c1a8daaee8 --- /dev/null +++ b/tencentcloud/resource_tc_cvm_import_image_test.go @@ -0,0 +1,56 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccTencentCloudNeedFixCvmImportImageResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCvmImportImage, + Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_cvm_import_image.import_image", "id")), + }, + { + ResourceName: "tencentcloud_cvm_import_image.import_image", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccCvmImportImage = ` + +resource "tencentcloud_cvm_import_image" "import_image" { + architecture = "x86_64" + os_type = "CentOS" + os_version = "7" + image_url = "" + image_name = "sample" + image_description = "sampleimage" + dry_run = false + force = false + tag_specification { + resource_type = "image" + tags { + key = "tagKey" + value = "tagValue" + } + + } + license_type = "TencentCloud" + boot_mode = "Legacy BIOS" + tags = { + "createdBy" = "terraform" + } +} + +` diff --git a/tencentcloud/resource_tc_cvm_modify_instance_disk_type.go b/tencentcloud/resource_tc_cvm_modify_instance_disk_type.go new file mode 100644 index 0000000000..515a55285b --- /dev/null +++ b/tencentcloud/resource_tc_cvm_modify_instance_disk_type.go @@ -0,0 +1,271 @@ +/* +Provides a resource to create a cvm modify_instance_disk_type + +Example Usage + +```hcl +resource "tencentcloud_cvm_modify_instance_disk_type" "modify_instance_disk_type" { + instance_id = "ins-r8hr2upy" + data_disks { + disk_size = 50 + disk_type = "CLOUD_BASIC" + disk_id = "disk-hrsd0u81" + delete_with_instance = true + snapshot_id = "snap-r9unnd89" + encrypt = false + kms_key_id = "kms-abcd1234" + throughput_performance = 2 + cdc_id = "cdc-b9pbd3px" + + } + system_disk { + disk_type = "CLOUD_PREMIUM" + disk_id = "disk-1drr53sd" + disk_size = 50 + cdc_id = "cdc-b9pbd3px" + + } +} +``` +*/ +package tencentcloud + +import ( + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudCvmModifyInstanceDiskType() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudCvmModifyInstanceDiskTypeCreate, + Read: resourceTencentCloudCvmModifyInstanceDiskTypeRead, + Delete: resourceTencentCloudCvmModifyInstanceDiskTypeDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "instance_id": { + Required: true, + ForceNew: true, + Type: schema.TypeString, + Description: "Instance ID. To obtain the instance IDs, you can call DescribeInstances and look for InstanceId in the response.", + }, + + "data_disks": { + Optional: true, + ForceNew: true, + Type: schema.TypeList, + Description: "For instance data disk configuration information, you only need to specify the media type of the target cloud disk to be converted, and specify the value of DiskType. Currently, only one data disk conversion is supported. The CdcId parameter is only supported for instances of the CDHPAID type.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "disk_size": { + Type: schema.TypeInt, + Required: true, + Description: "Data disk size (in GB). The minimum adjustment increment is 10 GB. The value range varies by data disk type. The default value is 0, indicating that no data disk is purchased. For more information, see the product documentation.", + }, + "disk_type": { + Type: schema.TypeString, + Optional: true, + Description: "Data disk type. Valid values:\n" + + "- LOCAL_BASIC: local hard disk;\n" + + "- LOCAL_SSD: local SSD hard disk;\n" + + "- LOCAL_NVME: local NVME hard disk, which is strongly related to InstanceType and cannot be specified;\n" + + "- LOCAL_PRO: local HDD hard disk, which is strongly related to InstanceType and cannot be specified;\n" + + "- CLOUD_BASIC: ordinary cloud disk;\n" + + "- CLOUD_PREMIUM: high-performance cloud disk;\n" + + "- CLOUD_SSD:SSD cloud disk;\n" + + "- CLOUD_HSSD: enhanced SSD cloud disk;\n" + + "- CLOUD_TSSD: extremely fast SSD cloud disk;\n" + + "- CLOUD_BSSD: general-purpose SSD cloud disk;\n" + + "Default value: LOCAL_BASIC.", + }, + "disk_id": { + Type: schema.TypeString, + Optional: true, + Description: "Data disk ID. Note that it's not available for LOCAL_BASIC and LOCAL_SSD disks.", + }, + "delete_with_instance": { + Type: schema.TypeBool, + Optional: true, + Description: "Whether to terminate the data disk when its CVM is terminated. Valid values:\n" + + "- TRUE: terminate the data disk when its CVM is terminated. This value only supports pay-as-you-go cloud disks billed on an hourly basis.\n" + + "- FALSE: retain the data disk when its CVM is terminated.\n" + + "Default value: TRUE.", + }, + "snapshot_id": { + Type: schema.TypeString, + Optional: true, + Description: "Data disk snapshot ID. The size of the selected data disk snapshot must be smaller than that of the data disk.", + }, + "encrypt": { + Type: schema.TypeBool, + Optional: true, + Description: "Specifies whether the data disk is encrypted. Valid values:\n" + + "- TRUE: encrypted\n" + + "- FALSE: not encrypted\n" + + "Default value: FALSE.", + }, + "kms_key_id": { + Type: schema.TypeString, + Optional: true, + Description: "ID of the custom CMK in the format of UUID or “kms-abcd1234”. This parameter is used to encrypt cloud disks.", + }, + "throughput_performance": { + Type: schema.TypeInt, + Optional: true, + Description: "Cloud disk performance, in MB/s.", + }, + "cdc_id": { + Type: schema.TypeString, + Optional: true, + Description: "ID of the dedicated cluster to which the instance belongs.", + }, + }, + }, + }, + + "system_disk": { + Optional: true, + ForceNew: true, + Type: schema.TypeList, + MaxItems: 1, + Description: "For instance system disk configuration information, you only need to specify the nature type of the target cloud disk to be converted, and specify the value of DiskType. Only CDHPAID type instances are supported to specify Cd.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "disk_type": { + Type: schema.TypeString, + Optional: true, + Description: "System disk type. Valid values:" + + "- LOCAL_BASIC: local disk\n" + + "- LOCAL_SSD: local SSD disk\n" + + "- CLOUD_BASIC: ordinary cloud disk\n" + + "- CLOUD_SSD: SSD cloud disk\n" + + "- CLOUD_PREMIUM: Premium cloud storage\n" + + "- CLOUD_BSSD: Balanced SSD\n" + + "The disk currently in stock will be used by default.", + }, + "disk_id": { + Type: schema.TypeString, + Optional: true, + Description: "System disk ID. System disks whose type is LOCAL_BASIC or LOCAL_SSD do not have an ID and do not support this parameter.", + }, + "disk_size": { + Type: schema.TypeInt, + Optional: true, + Description: "System disk size; unit: GB; default value: 50 GB.", + }, + "cdc_id": { + Type: schema.TypeString, + Optional: true, + Description: "ID of the dedicated cluster to which the instance belongs.", + }, + }, + }, + }, + }, + } +} + +func resourceTencentCloudCvmModifyInstanceDiskTypeCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cvm_modify_instance_disk_type.create")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + var ( + request = cvm.NewModifyInstanceDiskTypeRequest() + instanceId string + ) + if v, ok := d.GetOk("instance_id"); ok { + instanceId := v.(string) + request.InstanceId = helper.String(instanceId) + } + + if v, ok := d.GetOk("data_disks"); ok { + for _, item := range v.([]interface{}) { + dMap := item.(map[string]interface{}) + dataDisk := cvm.DataDisk{} + if v, ok := dMap["disk_size"]; ok { + dataDisk.DiskSize = helper.IntInt64(v.(int)) + } + if v, ok := dMap["disk_type"]; ok { + dataDisk.DiskType = helper.String(v.(string)) + } + if v, ok := dMap["disk_id"]; ok { + dataDisk.DiskId = helper.String(v.(string)) + } + if v, ok := dMap["delete_with_instance"]; ok { + dataDisk.DeleteWithInstance = helper.Bool(v.(bool)) + } + if v, ok := dMap["snapshot_id"]; ok { + dataDisk.SnapshotId = helper.String(v.(string)) + } + if v, ok := dMap["encrypt"]; ok { + dataDisk.Encrypt = helper.Bool(v.(bool)) + } + if v, ok := dMap["kms_key_id"]; ok { + dataDisk.KmsKeyId = helper.String(v.(string)) + } + if v, ok := dMap["throughput_performance"]; ok { + dataDisk.ThroughputPerformance = helper.IntInt64(v.(int)) + } + if v, ok := dMap["cdc_id"]; ok { + dataDisk.CdcId = helper.String(v.(string)) + } + request.DataDisks = append(request.DataDisks, &dataDisk) + } + } + + if dMap, ok := helper.InterfacesHeadMap(d, "system_disk"); ok { + systemDisk := cvm.SystemDisk{} + if v, ok := dMap["disk_type"]; ok { + systemDisk.DiskType = helper.String(v.(string)) + } + if v, ok := dMap["disk_id"]; ok { + systemDisk.DiskId = helper.String(v.(string)) + } + if v, ok := dMap["disk_size"]; ok { + systemDisk.DiskSize = helper.IntInt64(v.(int)) + } + if v, ok := dMap["cdc_id"]; ok { + systemDisk.CdcId = helper.String(v.(string)) + } + request.SystemDisk = &systemDisk + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseCvmClient().ModifyInstanceDiskType(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + if err != nil { + log.Printf("[CRITAL]%s operate cvm modifyInstanceDiskType failed, reason:%+v", logId, err) + return err + } + + d.SetId(instanceId) + + return resourceTencentCloudCvmModifyInstanceDiskTypeRead(d, meta) +} + +func resourceTencentCloudCvmModifyInstanceDiskTypeRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cvm_modify_instance_disk_type.read")() + defer inconsistentCheck(d, meta)() + + return nil +} + +func resourceTencentCloudCvmModifyInstanceDiskTypeDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cvm_modify_instance_disk_type.delete")() + defer inconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/resource_tc_cvm_modify_instance_disk_type_test.go b/tencentcloud/resource_tc_cvm_modify_instance_disk_type_test.go new file mode 100644 index 0000000000..b1d5c395fc --- /dev/null +++ b/tencentcloud/resource_tc_cvm_modify_instance_disk_type_test.go @@ -0,0 +1,55 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccTencentCloudNeedFixCvmModifyInstanceDiskTypeResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCvmModifyInstanceDiskType, + Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_cvm_modify_instance_disk_type.modify_instance_disk_type", "id")), + }, + { + ResourceName: "tencentcloud_cvm_modify_instance_disk_type.modify_instance_disk_type", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccCvmModifyInstanceDiskType = ` + +resource "tencentcloud_cvm_modify_instance_disk_type" "modify_instance_disk_type" { + instance_id = "ins-r8hr2upy" + data_disks { + disk_size = 50 + disk_type = "CLOUD_BASIC" + disk_id = "disk-hrsd0u81" + delete_with_instance = true + snapshot_id = "snap-r9unnd89" + encrypt = false + kms_key_id = "kms-abcd1234" + throughput_performance = 2 + cdc_id = "cdc-b9pbd3px" + + } + system_disk { + disk_type = "CLOUD_PREMIUM" + disk_id = "disk-1drr53sd" + disk_size = 50 + cdc_id = "cdc-b9pbd3px" + + } +} + +` diff --git a/tencentcloud/resource_tc_cvm_program_fpga_image.go b/tencentcloud/resource_tc_cvm_program_fpga_image.go new file mode 100644 index 0000000000..dedfaf9b39 --- /dev/null +++ b/tencentcloud/resource_tc_cvm_program_fpga_image.go @@ -0,0 +1,135 @@ +/* +Provides a resource to create a cvm program_fpga_image + +Example Usage + +```hcl +resource "tencentcloud_cvm_program_fpga_image" "program_fpga_image" { + instance_id = "ins-xxxxxx" + fpga_url = "" + dbd_fs = "" +} +``` + +Import + +cvm program_fpga_image can be imported using the id, e.g. + +``` +terraform import tencentcloud_cvm_program_fpga_image.program_fpga_image program_fpga_image_id +``` +*/ +package tencentcloud + +import ( + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudCvmProgramFpgaImage() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudCvmProgramFpgaImageCreate, + Read: resourceTencentCloudCvmProgramFpgaImageRead, + Delete: resourceTencentCloudCvmProgramFpgaImageDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "instance_id": { + Required: true, + ForceNew: true, + Type: schema.TypeString, + Description: "The ID information of the instance.", + }, + + "fpga_url": { + Required: true, + ForceNew: true, + Type: schema.TypeString, + Description: "COS URL address of the FPGA image file.", + }, + + "dbd_fs": { + Optional: true, + ForceNew: true, + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "The DBDF number of the FPGA card on the instance, if left blank, the FPGA image will be burned to all FPGA cards owned by the instance by default.", + }, + + "dry_run": { + Optional: true, + ForceNew: true, + Type: schema.TypeBool, + Description: "Trial run, will not perform the actual burning action, the default is False.", + }, + }, + } +} + +func resourceTencentCloudCvmProgramFpgaImageCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cvm_program_fpga_image.create")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + var ( + request = cvm.NewProgramFpgaImageRequest() + ) + instanceId := d.Get("instance_id").(string) + request.InstanceId = helper.String(instanceId) + + if v, ok := d.GetOk("fpga_url"); ok { + request.FPGAUrl = helper.String(v.(string)) + } + + if v, ok := d.GetOk("dbd_fs"); ok { + dBDFsSet := v.(*schema.Set).List() + for i := range dBDFsSet { + dBDFs := dBDFsSet[i].(string) + request.DBDFs = append(request.DBDFs, &dBDFs) + } + } + + if v, _ := d.GetOk("dry_run"); v != nil { + request.DryRun = helper.Bool(v.(bool)) + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseCvmClient().ProgramFpgaImage(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + if err != nil { + log.Printf("[CRITAL]%s operate cvm programFpgaImage failed, reason:%+v", logId, err) + return err + } + + d.SetId(instanceId) + + return resourceTencentCloudCvmProgramFpgaImageRead(d, meta) +} + +func resourceTencentCloudCvmProgramFpgaImageRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cvm_program_fpga_image.read")() + defer inconsistentCheck(d, meta)() + + return nil +} + +func resourceTencentCloudCvmProgramFpgaImageDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cvm_program_fpga_image.delete")() + defer inconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/resource_tc_cvm_program_fpga_image_test.go b/tencentcloud/resource_tc_cvm_program_fpga_image_test.go new file mode 100644 index 0000000000..6af00e59f0 --- /dev/null +++ b/tencentcloud/resource_tc_cvm_program_fpga_image_test.go @@ -0,0 +1,38 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccTencentCloudNeedFixCvmProgramFpgaImageResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCvmProgramFpgaImage, + Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_cvm_program_fpga_image.program_fpga_image", "id")), + }, + { + ResourceName: "tencentcloud_cvm_program_fpga_image.program_fpga_image", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccCvmProgramFpgaImage = ` + +resource "tencentcloud_cvm_program_fpga_image" "program_fpga_image" { + instance_id = "ins-xxxxxx" + fpga_url = "" + dbd_fs = "" +} + +` diff --git a/tencentcloud/resource_tc_cvm_renew_host.go b/tencentcloud/resource_tc_cvm_renew_host.go new file mode 100644 index 0000000000..cf703ba26b --- /dev/null +++ b/tencentcloud/resource_tc_cvm_renew_host.go @@ -0,0 +1,119 @@ +/* +Provides a resource to create a cvm renew_host + +Example Usage + +```hcl +resource "tencentcloud_cvm_renew_host" "renew_host" { + host_id = "xxxxxx" + host_charge_prepaid { + period = 1 + renew_flag = "NOTIFY_AND_MANUAL_RENEW" + } +} +``` +*/ +package tencentcloud + +import ( + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudCvmRenewHost() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudCvmRenewHostCreate, + Read: resourceTencentCloudCvmRenewHostRead, + Delete: resourceTencentCloudCvmRenewHostDelete, + Schema: map[string]*schema.Schema{ + "host_id": { + Required: true, + ForceNew: true, + Type: schema.TypeString, + Description: "CDH instance ID.", + }, + + "host_charge_prepaid": { + Required: true, + ForceNew: true, + Type: schema.TypeList, + MaxItems: 1, + Description: "Prepaid mode, that is, yearly and monthly subscription related parameter settings. Through this parameter, you can specify attributes such as the purchase duration of the Subscription instance and whether to set automatic renewal. If the payment mode of the specified instance is prepaid, this parameter must be passed.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "period": { + Type: schema.TypeInt, + Required: true, + Description: "The duration of purchasing an instance, unit: month. Value range: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36.", + }, + "renew_flag": { + Type: schema.TypeString, + Optional: true, + Description: "Auto renewal flag. Valid values:<br><li>NOTIFY_AND_AUTO_RENEW: notify upon expiration and renew automatically<br><li>NOTIFY_AND_MANUAL_RENEW: notify upon expiration but do not renew automatically<br><li>DISABLE_NOTIFY_AND_MANUAL_RENEW: neither notify upon expiration nor renew automatically<br><br>Default value: NOTIFY_AND_AUTO_RENEW。If this parameter is specified as NOTIFY_AND_AUTO_RENEW, the instance will be automatically renewed on a monthly basis if the account balance is sufficient.", + }, + }, + }, + }, + }, + } +} + +func resourceTencentCloudCvmRenewHostCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cvm_renew_host.create")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + var ( + request = cvm.NewRenewHostsRequest() + ) + hostId := d.Get("host_id").(string) + request.HostIds = []*string{&hostId} + + if dMap, ok := helper.InterfacesHeadMap(d, "host_charge_prepaid"); ok { + chargePrepaid := cvm.ChargePrepaid{} + if v, ok := dMap["period"]; ok { + chargePrepaid.Period = helper.IntUint64(v.(int)) + } + if v, ok := dMap["renew_flag"]; ok { + chargePrepaid.RenewFlag = helper.String(v.(string)) + } + request.HostChargePrepaid = &chargePrepaid + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseCvmClient().RenewHosts(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + if err != nil { + log.Printf("[CRITAL]%s operate cvm renewHost failed, reason:%+v", logId, err) + return err + } + + d.SetId(hostId) + + return resourceTencentCloudCvmRenewHostRead(d, meta) +} + +func resourceTencentCloudCvmRenewHostRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cvm_renew_host.read")() + defer inconsistentCheck(d, meta)() + + return nil +} + +func resourceTencentCloudCvmRenewHostDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cvm_renew_host.delete")() + defer inconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/resource_tc_cvm_renew_host_test.go b/tencentcloud/resource_tc_cvm_renew_host_test.go new file mode 100644 index 0000000000..65e20ce5f9 --- /dev/null +++ b/tencentcloud/resource_tc_cvm_renew_host_test.go @@ -0,0 +1,41 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccTencentCloudNeedFixCvmRenewHostResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCvmRenewHost, + Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_cvm_renew_host.renew_host", "id")), + }, + { + ResourceName: "tencentcloud_cvm_renew_host.renew_host", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccCvmRenewHost = ` + +resource "tencentcloud_cvm_renew_host" "renew_host" { + host_ids = + host_charge_prepaid { + period = 1 + renew_flag = "NOTIFY_AND_MANUAL_RENEW" + + } +} + +`