in alicloud/resource_alicloud_instance.go [23:701]
func resourceAliCloudInstance() *schema.Resource {
return &schema.Resource{
Create: resourceAliCloudInstanceCreate,
Read: resourceAliCloudInstanceRead,
Update: resourceAliCloudInstanceUpdate,
Delete: resourceAliCloudInstanceDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Update: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(20 * time.Minute),
},
Schema: map[string]*schema.Schema{
"availability_zone": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
"image_id": {
Type: schema.TypeString,
AtLeastOneOf: []string{"image_id", "launch_template_id", "launch_template_name"},
Optional: true,
Computed: true,
},
"instance_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: StringMatch(regexp.MustCompile(`^ecs\..*`), "prefix must be 'ecs.'"),
AtLeastOneOf: []string{"instance_type", "launch_template_id", "launch_template_name"},
Computed: true,
},
"credit_specification": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: StringInSlice([]string{
string(CreditSpecificationStandard),
string(CreditSpecificationUnlimited),
}, false),
},
"security_groups": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
Optional: true,
AtLeastOneOf: []string{"security_groups", "launch_template_id", "launch_template_name"},
},
"allocate_public_ip": {
Type: schema.TypeBool,
Optional: true,
Deprecated: "Field 'allocate_public_ip' has been deprecated from provider version 1.6.1. Setting 'internet_max_bandwidth_out' larger than 0 will allocate public ip for instance.",
},
"instance_name": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: StringLenBetween(2, 128),
Computed: true,
},
"resource_group_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: StringLenBetween(2, 256),
Computed: true,
},
"internet_charge_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: StringInSlice([]string{"PayByBandwidth", "PayByTraffic"}, false),
DiffSuppressFunc: ecsInternetDiffSuppressFunc,
Computed: true,
},
"internet_max_bandwidth_in": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
DiffSuppressFunc: ecsInternetDiffSuppressFunc,
Deprecated: "The attribute is invalid and no any affect for the instance. So it has been deprecated since version v1.121.2.",
},
"internet_max_bandwidth_out": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"host_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"password": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
},
"kms_encrypted_password": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: kmsDiffSuppressFunc,
},
"kms_encryption_context": {
Type: schema.TypeMap,
Optional: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return d.Get("kms_encrypted_password") == ""
},
Elem: schema.TypeString,
},
"password_inherit": {
Type: schema.TypeBool,
Optional: true,
},
"io_optimized": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Deprecated: "Attribute io_optimized has been deprecated on instance resource. All the launched alicloud instances will be IO optimized. Suggest to remove it from your template.",
Removed: "Attribute 'io_optimized' has been removed from provider version 1.213.1.",
},
"is_outdated": {
Type: schema.TypeBool,
Optional: true,
},
"system_disk_category": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: StringInSlice([]string{"all", "cloud", "ephemeral_ssd", "cloud_essd", "cloud_efficiency", "cloud_ssd", "local_disk", "cloud_auto", "cloud_essd_entry"}, false),
},
"system_disk_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: StringLenBetween(2, 128),
},
"system_disk_description": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: StringLenBetween(2, 256),
},
"system_disk_size": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"system_disk_performance_level": {
Type: schema.TypeString,
Optional: true,
Computed: true,
DiffSuppressFunc: ecsSystemDiskPerformanceLevelSuppressFunc,
ValidateFunc: StringInSlice([]string{"PL0", "PL1", "PL2", "PL3"}, false),
},
"system_disk_auto_snapshot_policy_id": {
Type: schema.TypeString,
Optional: true,
},
"system_disk_storage_cluster_id": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
},
"system_disk_encrypted": {
Type: schema.TypeBool,
ForceNew: true,
Optional: true,
Computed: true,
},
"system_disk_kms_key_id": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Computed: true,
},
"system_disk_encrypt_algorithm": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
},
"system_disk_id": {
Type: schema.TypeString,
Computed: true,
},
"network_interface_traffic_mode": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: StringInSlice([]string{"Standard", "HighPerformance"}, false),
},
"network_card_index": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
"queue_pair_number": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
"data_disks": {
Type: schema.TypeList,
Optional: true,
MinItems: 1,
MaxItems: 16,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: StringLenBetween(2, 128),
},
"size": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
},
"category": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: StringInSlice([]string{"all", "cloud", "ephemeral_ssd", "cloud_essd", "cloud_efficiency", "cloud_ssd", "local_disk", "cloud_auto", "cloud_essd_entry"}, false),
Default: DiskCloudEfficiency,
ForceNew: true,
},
"encrypted": {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
},
"kms_key_id": {
Type: schema.TypeString,
Optional: true,
},
"snapshot_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"auto_snapshot_policy_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"delete_with_instance": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Default: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: StringLenBetween(2, 256),
},
"performance_level": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: StringInSlice([]string{"PL0", "PL1", "PL2", "PL3"}, false),
},
"device": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
},
},
},
"network_interfaces": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"network_interface_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
"vswitch_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
"network_interface_traffic_mode": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: StringInSlice([]string{"Standard", "HighPerformance"}, false),
},
"network_card_index": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Computed: true,
},
"queue_pair_number": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Computed: true,
},
"security_group_ids": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
//subnet_id and vswitch_id both exists, cause compatible old version, and aws habit.
"subnet_id": {
Type: schema.TypeString,
Optional: true,
Computed: true, //add this schema cause subnet_id not used enter parameter, will different, so will be ForceNew
Removed: "Field 'subnet_id' has been removed from version 1.210.0",
},
"vpc_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"vswitch_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"private_ip": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"instance_charge_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: StringInSlice([]string{string(common.PrePaid), string(common.PostPaid)}, false),
},
"period": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.Any(
IntBetween(1, 9),
IntInSlice([]int{12, 24, 36, 48, 60})),
DiffSuppressFunc: PostPaidDiffSuppressFunc,
},
"period_unit": {
Type: schema.TypeString,
Optional: true,
Default: Month,
ValidateFunc: StringInSlice([]string{"Week", "Month"}, false),
DiffSuppressFunc: PostPaidDiffSuppressFunc,
},
"renewal_status": {
Type: schema.TypeString,
Optional: true,
Default: RenewNormal,
ValidateFunc: StringInSlice([]string{
string(RenewAutoRenewal),
string(RenewNormal),
string(RenewNotRenewal)}, false),
DiffSuppressFunc: PostPaidDiffSuppressFunc,
},
"auto_renew_period": {
Type: schema.TypeInt,
Optional: true,
Default: 1,
ValidateFunc: IntInSlice([]int{1, 2, 3, 6, 12}),
DiffSuppressFunc: ecsNotAutoRenewDiffSuppressFunc,
},
"include_data_disks": {
Type: schema.TypeBool,
Optional: true,
Default: true,
DiffSuppressFunc: PostPaidDiffSuppressFunc,
},
"dry_run": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"public_ip": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: StringInSlice([]string{"Running", "Stopped"}, false),
Computed: true,
},
"user_data": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if (d.Get("user_data") != "" && new == "") && (d.Get("launch_template_name").(string) != "" ||
d.Get("launch_template_id").(string) != "") {
return true
}
return false
},
},
"role_name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
DiffSuppressFunc: vpcTypeResourceDiffSuppressFunc,
},
"key_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"spot_strategy": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: StringInSlice([]string{"NoSpot", "SpotAsPriceGo", "SpotWithPriceLimit"}, false),
DiffSuppressFunc: ecsSpotStrategyDiffSuppressFunc,
},
"spot_price_limit": {
Type: schema.TypeFloat,
Optional: true,
ForceNew: true,
Computed: true,
DiffSuppressFunc: ecsSpotPriceLimitDiffSuppressFunc,
},
"deletion_protection": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"force_delete": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: descriptions["A behavior mark used to delete 'PrePaid' ECS instance forcibly."],
DiffSuppressFunc: PostPaidDiffSuppressFunc,
},
"security_enhancement_strategy": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: StringInSlice([]string{
string(ActiveSecurityEnhancementStrategy),
string(DeactiveSecurityEnhancementStrategy),
}, false),
},
"tags": tagsSchemaWithIgnore(),
"volume_tags": tagsSchemaComputed(),
"auto_release_time": {
Type: schema.TypeString,
Optional: true,
//ValidateFunc: ValidateRFC3339TimeString(true),
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if (d.Get("auto_release_time") != "" && new == "") && (d.Get("launch_template_name").(string) != "" ||
d.Get("launch_template_id").(string) != "") {
return true
}
if d.Get("instance_charge_type").(string) == "PrePaid" {
return true
}
return old != "" && new != "" && strings.HasPrefix(new, strings.Trim(old, ":00Z"))
},
},
"hpc_cluster_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"secondary_private_ips": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Computed: true,
ConflictsWith: []string{"secondary_private_ip_address_count"},
},
"secondary_private_ip_address_count": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ConflictsWith: []string{"secondary_private_ips"},
},
"deployment_set_id": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if (d.Get("deployment_set_id") != "" && new == "") && (d.Get("launch_template_name").(string) != "" ||
d.Get("launch_template_id").(string) != "") {
return true
}
return false
},
},
"deployment_set_group_no": {
Type: schema.TypeString,
Computed: true,
},
"operator_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: StringInSlice([]string{"upgrade", "downgrade"}, false),
},
"stopped_mode": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ValidateFunc: StringInSlice([]string{"StopCharging", "KeepCharging", "Not-applicable"}, false),
},
"maintenance_time": {
Type: schema.TypeSet,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"start_time": {
Type: schema.TypeString,
Optional: true,
},
"end_time": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
"maintenance_action": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: StringInSlice([]string{"Stop", "AutoRecover", "AutoRedeploy"}, false),
},
"maintenance_notify": {
Type: schema.TypeBool,
Optional: true,
},
"spot_duration": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: IntBetween(0, 6),
},
"http_tokens": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: StringInSlice([]string{"optional", "required"}, false),
},
"http_endpoint": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: StringInSlice([]string{"enabled", "disabled"}, false),
},
"http_put_response_hop_limit": {
Type: schema.TypeInt,
ForceNew: true,
Optional: true,
Computed: true,
ValidateFunc: IntBetween(1, 64),
},
"ipv6_address_count": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: IntBetween(1, 10),
ConflictsWith: []string{"ipv6_addresses"},
},
"ipv6_addresses": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
MaxItems: 10,
Elem: &schema.Schema{Type: schema.TypeString},
ConflictsWith: []string{"ipv6_address_count"},
},
"network_interface_id": {
Type: schema.TypeString,
Computed: true,
},
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"memory": {
Type: schema.TypeInt,
Computed: true,
},
"os_name": {
Type: schema.TypeString,
Computed: true,
},
"os_type": {
Type: schema.TypeString,
Computed: true,
},
"primary_ip_address": {
Type: schema.TypeString,
Computed: true,
},
"dedicated_host_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"spot_strategy", "spot_price_limit"},
},
"launch_template_name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"launch_template_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"launch_template_version": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"enable_jumbo_frame": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"create_time": {
Type: schema.TypeString,
Computed: true,
},
"start_time": {
Type: schema.TypeString,
Computed: true,
},
"expired_time": {
Type: schema.TypeString,
Computed: true,
},
"image_options": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"login_as_non_root": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
},
},
},
},
}
}