diff --git a/docs/index.md b/docs/index.md index e27ffd62..e31681af 100644 --- a/docs/index.md +++ b/docs/index.md @@ -95,7 +95,7 @@ resource "gcore_volume" "third_volume" { project_id = var.project_id } -resource "gcore_instance" "instance" { +resource "gcore_instancev2" "instance" { flavor_id = "g1-standard-2-4" name = "test_instance_1" keypair_name = gcore_keypair.kp.sshkey_name @@ -164,12 +164,12 @@ resource "gcore_lbmember" "lbm" { project_id = var.project_id region_id = var.region_id pool_id = gcore_lbpool.pl.id - instance_id = gcore_instance.instance.id - address = tolist(gcore_instance.instance.interface).0.ip_address + instance_id = gcore_instancev2.instance.id + address = tolist(gcore_instancev2.instance.interface).0.ip_address protocol_port = 8081 } -resource "gcore_instance" "instance2" { +resource "gcore_instancev2" "instance2" { flavor_id = "g1-standard-2-4" name = "test_instance_2" keypair_name = gcore_keypair.kp.sshkey_name @@ -205,8 +205,8 @@ resource "gcore_lbmember" "lbm2" { project_id = var.project_id region_id = var.region_id pool_id = gcore_lbpool.pl.id - instance_id = gcore_instance.instance2.id - address = tolist(gcore_instance.instance2.interface).0.ip_address + instance_id = gcore_instancev2.instance2.id + address = tolist(gcore_instancev2.instance2.interface).0.ip_address protocol_port = 8081 weight = 5 } diff --git a/docs/resources/instancev2.md b/docs/resources/instancev2.md index 6c215891..cf06aef4 100644 --- a/docs/resources/instancev2.md +++ b/docs/resources/instancev2.md @@ -55,7 +55,7 @@ data "gcore_image" "ubuntu" { } resource "gcore_volume" "boot_volume" { - name = "boot volume" + name = "my-boot-volume" type_name = "ssd_hiiops" size = 5 image_id = data.gcore_image.ubuntu.id @@ -81,7 +81,6 @@ resource "gcore_instancev2" "instance" { keypair_name = "my-keypair" volume { - source = "existing-volume" volume_id = gcore_volume.boot_volume.id boot_index = 0 } @@ -107,7 +106,6 @@ resource "gcore_instancev2" "instance" { keypair_name = "my-keypair" volume { - source = "existing-volume" volume_id = gcore_volume.boot_volume.id boot_index = 0 } @@ -139,7 +137,7 @@ data "gcore_image" "windows" { } resource "gcore_volume" "boot_volume_windows" { - name = "windows boot volume" + name = "my-windows-boot-volume" type_name = "ssd_hiiops" size = 50 image_id = data.gcore_image.windows.id @@ -194,7 +192,6 @@ resource "gcore_instancev2" "instance" { keypair_name = "my-keypair" volume { - source = "existing-volume" volume_id = gcore_volume.boot_volume.id boot_index = 0 } @@ -204,7 +201,6 @@ resource "gcore_instancev2" "instance" { name = "my-floating-ip-interface" port_id = gcore_reservedfixedip.fixed_ip.port_id - fip_source = "existing" existing_fip_id = gcore_floatingip.floating_ip.id } @@ -228,7 +224,6 @@ resource "gcore_instancev2" "instance" { keypair_name = "my-keypair" volume { - source = "existing-volume" volume_id = gcore_volume.boot_volume.id boot_index = 0 } @@ -305,7 +300,6 @@ resource "gcore_instancev2" "instance" { keypair_name = "my-keypair" volume { - source = "existing-volume" volume_id = gcore_volume.boot_volume.id boot_index = 0 } @@ -328,8 +322,12 @@ resource "gcore_instancev2" "instance" { This example shows how to create a Windows instance with two users. The second user is added by using the userdata feature to automate the creation process. -userdata: -```userdata + +```terraform +variable "second_user_userdata" { + description = "This is a variable of type string" + type = string + default = < # Be sure to set the username and password on these two lines. Of course this is not a good # security practice to include a password at command line. @@ -339,9 +337,9 @@ New-LocalUser $User -Password $Password Add-LocalGroupMember -Group "Remote Desktop Users" -Member $User Add-LocalGroupMember -Group "Administrators" -Member $User -``` +EOF +} -```terraform data "gcore_image" "windows" { name = "windows-server-2022" region_id = data.gcore_region.region.id @@ -349,7 +347,7 @@ data "gcore_image" "windows" { } resource "gcore_volume" "boot_volume_windows" { - name = "windows boot volume" + name = "my-windows-boot-volume" type_name = "ssd_hiiops" size = 50 image_id = data.gcore_image.windows.id @@ -361,10 +359,9 @@ resource "gcore_instancev2" "instance" { flavor_id = "g1w-standard-4-8" name = "my-windows-instance" password = "my-s3cR3tP@ssw0rd" - user_data = "PHBvd2Vyc2hlbGw+CiMgQmUgc3VyZSB0byBzZXQgdGhlIHVzZXJuYW1lIGFuZCBwYXNzd29yZCBvbiB0aGVzZSB0d28gbGluZXMuIE9mIGNvdXJzZSB0aGlzIGlzIG5vdCBhIGdvb2QKIyBzZWN1cml0eSBwcmFjdGljZSB0byBpbmNsdWRlIGEgcGFzc3dvcmQgYXQgY29tbWFuZCBsaW5lLgokVXNlciA9ICJTZWNvbmRVc2VyIgokUGFzc3dvcmQgPSBDb252ZXJ0VG8tU2VjdXJlU3RyaW5nICJzM2NSM3RQQHNzdzByZCIgLUFzUGxhaW5UZXh0IC1Gb3JjZQpOZXctTG9jYWxVc2VyICRVc2VyIC1QYXNzd29yZCAkUGFzc3dvcmQKQWRkLUxvY2FsR3JvdXBNZW1iZXIgLUdyb3VwICJSZW1vdGUgRGVza3RvcCBVc2VycyIgLU1lbWJlciAkVXNlcgpBZGQtTG9jYWxHcm91cE1lbWJlciAtR3JvdXAgIkFkbWluaXN0cmF0b3JzIiAtTWVtYmVyICRVc2VyCjwvcG93ZXJzaGVsbD4=" + user_data = base64encode(var.second_user_userdata) volume { - source = "existing-volume" volume_id = gcore_volume.boot_volume_windows.id boot_index = 0 } @@ -436,7 +433,6 @@ Required: Optional: - `existing_fip_id` (String) -- `fip_source` (String) - `ip_address` (String) - `network_id` (String) required if type is 'subnet' or 'any_subnet' - `order` (Number) Order of attaching interface @@ -467,10 +463,6 @@ Required: ### Nested Schema for `volume` -Required: - -- `source` (String) Currently available only 'existing-volume' value - Optional: - `attachment_tag` (String) diff --git a/docs/resources/k8sv2.md b/docs/resources/k8sv2.md index 3781e33a..171dfd96 100644 --- a/docs/resources/k8sv2.md +++ b/docs/resources/k8sv2.md @@ -84,7 +84,6 @@ output "kubeconfig" { - `id` (String) The ID of this resource. - `is_public` (Boolean) True if the cluster is public. - `security_group_id` (String) Security group ID. -- `security_group_rules_internal` (List of Object) Default readonly security group rules. It is used for internal purposes only. (see [below for nested schema](#nestedatt--security_group_rules_internal)) - `status` (String) Cluster status. - `task_id` (String) @@ -198,23 +197,6 @@ Optional: - `create` (String) - `update` (String) - - -### Nested Schema for `security_group_rules_internal` - -Read-Only: - -- `created_at` (String) -- `description` (String) -- `direction` (String) -- `ethertype` (String) -- `id` (String) -- `port_range_max` (Number) -- `port_range_min` (Number) -- `protocol` (String) -- `remote_ip_prefix` (String) -- `updated_at` (String) - ## Import Import is supported using the following syntax: diff --git a/docs/resources/lbmember.md b/docs/resources/lbmember.md index 445a6eb7..531d51e6 100644 --- a/docs/resources/lbmember.md +++ b/docs/resources/lbmember.md @@ -174,7 +174,7 @@ resource "gcore_volume" "instance_member_volume" { } -resource "gcore_instance" "instance_member" { +resource "gcore_instancev2" "instance_member" { project_id = data.gcore_project.project.id region_id = data.gcore_region.region.id @@ -189,6 +189,7 @@ resource "gcore_instance" "instance_member" { interface { type = "reserved_fixed_ip" + name = "my-private-network-interface" port_id = gcore_reservedfixedip.instance_member_fixed_ip.port_id } } @@ -199,7 +200,7 @@ resource "gcore_lbmember" "instance_member" { pool_id = gcore_lbpool.http.id - instance_id = gcore_instance.instance_member.id + instance_id = gcore_instancev2.instance_member.id address = gcore_reservedfixedip.instance_member_fixed_ip.fixed_ip_address protocol_port = 80 weight = 1 diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index 72f9ec98..720ba313 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -80,7 +80,7 @@ resource "gcore_volume" "third_volume" { project_id = var.project_id } -resource "gcore_instance" "instance" { +resource "gcore_instancev2" "instance" { flavor_id = "g1-standard-2-4" name = "test_instance_1" keypair_name = gcore_keypair.kp.sshkey_name @@ -149,12 +149,12 @@ resource "gcore_lbmember" "lbm" { project_id = var.project_id region_id = var.region_id pool_id = gcore_lbpool.pl.id - instance_id = gcore_instance.instance.id - address = tolist(gcore_instance.instance.interface).0.ip_address + instance_id = gcore_instancev2.instance.id + address = tolist(gcore_instancev2.instance.interface).0.ip_address protocol_port = 8081 } -resource "gcore_instance" "instance2" { +resource "gcore_instancev2" "instance2" { flavor_id = "g1-standard-2-4" name = "test_instance_2" keypair_name = gcore_keypair.kp.sshkey_name @@ -190,8 +190,8 @@ resource "gcore_lbmember" "lbm2" { project_id = var.project_id region_id = var.region_id pool_id = gcore_lbpool.pl.id - instance_id = gcore_instance.instance2.id - address = tolist(gcore_instance.instance2.interface).0.ip_address + instance_id = gcore_instancev2.instance2.id + address = tolist(gcore_instancev2.instance2.interface).0.ip_address protocol_port = 8081 weight = 5 } diff --git a/examples/resources/gcore_instancev2/custom-sg.tf b/examples/resources/gcore_instancev2/custom-sg.tf index 4a0dab1c..f524e8da 100644 --- a/examples/resources/gcore_instancev2/custom-sg.tf +++ b/examples/resources/gcore_instancev2/custom-sg.tf @@ -51,7 +51,6 @@ resource "gcore_instancev2" "instance" { keypair_name = "my-keypair" volume { - source = "existing-volume" volume_id = gcore_volume.boot_volume.id boot_index = 0 } diff --git a/examples/resources/gcore_instancev2/fip.tf b/examples/resources/gcore_instancev2/fip.tf index 842af212..f96cf8c0 100644 --- a/examples/resources/gcore_instancev2/fip.tf +++ b/examples/resources/gcore_instancev2/fip.tf @@ -19,7 +19,6 @@ resource "gcore_instancev2" "instance" { keypair_name = "my-keypair" volume { - source = "existing-volume" volume_id = gcore_volume.boot_volume.id boot_index = 0 } @@ -29,7 +28,6 @@ resource "gcore_instancev2" "instance" { name = "my-floating-ip-interface" port_id = gcore_reservedfixedip.fixed_ip.port_id - fip_source = "existing" existing_fip_id = gcore_floatingip.floating_ip.id } diff --git a/examples/resources/gcore_instancev2/main.tf b/examples/resources/gcore_instancev2/main.tf index 148737ab..50a034ba 100644 --- a/examples/resources/gcore_instancev2/main.tf +++ b/examples/resources/gcore_instancev2/main.tf @@ -33,7 +33,7 @@ data "gcore_image" "ubuntu" { } resource "gcore_volume" "boot_volume" { - name = "boot volume" + name = "my-boot-volume" type_name = "ssd_hiiops" size = 5 image_id = data.gcore_image.ubuntu.id diff --git a/examples/resources/gcore_instancev2/one-interface-windows.tf b/examples/resources/gcore_instancev2/one-interface-windows.tf index c8cfaec5..adce127a 100644 --- a/examples/resources/gcore_instancev2/one-interface-windows.tf +++ b/examples/resources/gcore_instancev2/one-interface-windows.tf @@ -5,7 +5,7 @@ data "gcore_image" "windows" { } resource "gcore_volume" "boot_volume_windows" { - name = "windows boot volume" + name = "my-windows-boot-volume" type_name = "ssd_hiiops" size = 50 image_id = data.gcore_image.windows.id diff --git a/examples/resources/gcore_instancev2/one-interface.tf b/examples/resources/gcore_instancev2/one-interface.tf index a3cfb90a..90ff85da 100644 --- a/examples/resources/gcore_instancev2/one-interface.tf +++ b/examples/resources/gcore_instancev2/one-interface.tf @@ -4,7 +4,6 @@ resource "gcore_instancev2" "instance" { keypair_name = "my-keypair" volume { - source = "existing-volume" volume_id = gcore_volume.boot_volume.id boot_index = 0 } diff --git a/examples/resources/gcore_instancev2/reserved-address.tf b/examples/resources/gcore_instancev2/reserved-address.tf index 1d6973e8..8007ee14 100644 --- a/examples/resources/gcore_instancev2/reserved-address.tf +++ b/examples/resources/gcore_instancev2/reserved-address.tf @@ -10,7 +10,6 @@ resource "gcore_instancev2" "instance" { keypair_name = "my-keypair" volume { - source = "existing-volume" volume_id = gcore_volume.boot_volume.id boot_index = 0 } diff --git a/examples/resources/gcore_instancev2/two-interface.tf b/examples/resources/gcore_instancev2/two-interface.tf index 07bace63..21c1b161 100644 --- a/examples/resources/gcore_instancev2/two-interface.tf +++ b/examples/resources/gcore_instancev2/two-interface.tf @@ -4,7 +4,6 @@ resource "gcore_instancev2" "instance" { keypair_name = "my-keypair" volume { - source = "existing-volume" volume_id = gcore_volume.boot_volume.id boot_index = 0 } diff --git a/examples/resources/gcore_instancev2/windows-with-userdata.tf b/examples/resources/gcore_instancev2/windows-with-userdata.tf index c2ec507c..23e361ff 100644 --- a/examples/resources/gcore_instancev2/windows-with-userdata.tf +++ b/examples/resources/gcore_instancev2/windows-with-userdata.tf @@ -1,3 +1,19 @@ +variable "second_user_userdata" { + description = "This is a variable of type string" + type = string + default = < +# Be sure to set the username and password on these two lines. Of course this is not a good +# security practice to include a password at command line. +$User = "SecondUser" +$Password = ConvertTo-SecureString "s3cR3tP@ssw0rd" -AsPlainText -Force +New-LocalUser $User -Password $Password +Add-LocalGroupMember -Group "Remote Desktop Users" -Member $User +Add-LocalGroupMember -Group "Administrators" -Member $User + +EOF +} + data "gcore_image" "windows" { name = "windows-server-2022" region_id = data.gcore_region.region.id @@ -5,7 +21,7 @@ data "gcore_image" "windows" { } resource "gcore_volume" "boot_volume_windows" { - name = "windows boot volume" + name = "my-windows-boot-volume" type_name = "ssd_hiiops" size = 50 image_id = data.gcore_image.windows.id @@ -17,10 +33,9 @@ resource "gcore_instancev2" "instance" { flavor_id = "g1w-standard-4-8" name = "my-windows-instance" password = "my-s3cR3tP@ssw0rd" - user_data = "PHBvd2Vyc2hlbGw+CiMgQmUgc3VyZSB0byBzZXQgdGhlIHVzZXJuYW1lIGFuZCBwYXNzd29yZCBvbiB0aGVzZSB0d28gbGluZXMuIE9mIGNvdXJzZSB0aGlzIGlzIG5vdCBhIGdvb2QKIyBzZWN1cml0eSBwcmFjdGljZSB0byBpbmNsdWRlIGEgcGFzc3dvcmQgYXQgY29tbWFuZCBsaW5lLgokVXNlciA9ICJTZWNvbmRVc2VyIgokUGFzc3dvcmQgPSBDb252ZXJ0VG8tU2VjdXJlU3RyaW5nICJzM2NSM3RQQHNzdzByZCIgLUFzUGxhaW5UZXh0IC1Gb3JjZQpOZXctTG9jYWxVc2VyICRVc2VyIC1QYXNzd29yZCAkUGFzc3dvcmQKQWRkLUxvY2FsR3JvdXBNZW1iZXIgLUdyb3VwICJSZW1vdGUgRGVza3RvcCBVc2VycyIgLU1lbWJlciAkVXNlcgpBZGQtTG9jYWxHcm91cE1lbWJlciAtR3JvdXAgIkFkbWluaXN0cmF0b3JzIiAtTWVtYmVyICRVc2VyCjwvcG93ZXJzaGVsbD4=" + user_data = base64encode(var.second_user_userdata) volume { - source = "existing-volume" volume_id = gcore_volume.boot_volume_windows.id boot_index = 0 } diff --git a/examples/resources/gcore_lbmember/instance-member.tf b/examples/resources/gcore_lbmember/instance-member.tf index f22b49ab..0b8be33e 100644 --- a/examples/resources/gcore_lbmember/instance-member.tf +++ b/examples/resources/gcore_lbmember/instance-member.tf @@ -43,7 +43,7 @@ resource "gcore_volume" "instance_member_volume" { } -resource "gcore_instance" "instance_member" { +resource "gcore_instancev2" "instance_member" { project_id = data.gcore_project.project.id region_id = data.gcore_region.region.id @@ -58,6 +58,7 @@ resource "gcore_instance" "instance_member" { interface { type = "reserved_fixed_ip" + name = "my-private-network-interface" port_id = gcore_reservedfixedip.instance_member_fixed_ip.port_id } } @@ -68,7 +69,7 @@ resource "gcore_lbmember" "instance_member" { pool_id = gcore_lbpool.http.id - instance_id = gcore_instance.instance_member.id + instance_id = gcore_instancev2.instance_member.id address = gcore_reservedfixedip.instance_member_fixed_ip.fixed_ip_address protocol_port = 80 weight = 1 diff --git a/gcore/resource_gcore_instancev2.go b/gcore/resource_gcore_instancev2.go index 80cad307..ed97d284 100644 --- a/gcore/resource_gcore_instancev2.go +++ b/gcore/resource_gcore_instancev2.go @@ -17,7 +17,6 @@ import ( "github.com/G-Core/gcorelabscloud-go/gcore/instance/v1/types" "github.com/G-Core/gcorelabscloud-go/gcore/task/v1/tasks" "github.com/G-Core/gcorelabscloud-go/gcore/volume/v1/volumes" - "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -120,18 +119,6 @@ your applications.`, Type: schema.TypeString, Optional: true, }, - "source": { - Type: schema.TypeString, - Required: true, - Description: "Currently available only 'existing-volume' value", - ValidateDiagFunc: func(val interface{}, key cty.Path) diag.Diagnostics { - v := val.(string) - if types.VolumeSource(v) == types.ExistingVolume { - return diag.Diagnostics{} - } - return diag.Errorf("wrong source type %s, now available values is '%s'", v, types.ExistingVolume) - }, - }, "boot_index": { Type: schema.TypeInt, Description: "If boot_index==0 volumes can not detached", @@ -206,10 +193,6 @@ your applications.`, Computed: true, }, // nested map is not supported, in this case, you do not need to use the list for the map - "fip_source": { - Type: schema.TypeString, - Optional: true, - }, "existing_fip_id": { Type: schema.TypeString, Optional: true, @@ -535,6 +518,11 @@ func resourceInstanceV2Read(ctx context.Context, d *schema.ResourceData, m inter return diag.FromErr(err) } + clientVol, err := CreateClient(provider, d, volumesPoint, versionPointV1) + if err != nil { + return diag.FromErr(err) + } + instance, err := instances.Get(client, instanceID).Extract() if err != nil { switch err.(type) { @@ -568,11 +556,17 @@ func resourceInstanceV2Read(ctx context.Context, d *schema.ResourceData, m inter if !ok { v = make(map[string]interface{}) v["volume_id"] = vol.ID - v["source"] = types.ExistingVolume.String() } - v["id"] = vol.ID v["delete_on_termination"] = vol.DeleteOnTermination + + volume, err := volumes.Get(clientVol, vol.ID).Extract() + if err != nil { + return diag.FromErr(err) + } + v["size"] = volume.Size + v["type_name"] = volume.VolumeType.String() + extVolumes = append(extVolumes, v) } @@ -636,7 +630,6 @@ func resourceInstanceV2Read(ctx context.Context, d *schema.ResourceData, m inter i["name"] = *iface.Name i["order"] = orderedIOpts.Order if len(iface.FloatingIPDetails) > 0 { - i["fip_source"] = types.ExistingFloatingIP i["existing_fip_id"] = iface.FloatingIPDetails[0].ID } i["ip_address"] = assignment.IPAddress.String() diff --git a/gcore/utils.go b/gcore/utils.go index 9a56df13..c7f484b9 100644 --- a/gcore/utils.go +++ b/gcore/utils.go @@ -207,6 +207,7 @@ func extractVolumesMap(volumes []interface{}) ([]instances.CreateVolumeOpts, err if err != nil { return nil, err } + V.Source = types.ExistingVolume Volumes[i] = V } return Volumes, nil @@ -242,14 +243,10 @@ func extractInstanceInterfacesMapV2(interfaces []interface{}) ([]instances.Inter return nil, err } - if inter["fip_source"] != "" { - var fip instances.CreateNewInterfaceFloatingIPOpts - if inter["existing_fip_id"] != "" { - fip.Source = types.ExistingFloatingIP - fip.ExistingFloatingID = inter["existing_fip_id"].(string) - } else { - fip.Source = types.NewFloatingIP - } + var fip instances.CreateNewInterfaceFloatingIPOpts + if inter["existing_fip_id"] != "" { + fip.Source = types.ExistingFloatingIP + fip.ExistingFloatingID = inter["existing_fip_id"].(string) I.FloatingIP = &fip } diff --git a/templates/resources/instancev2.md.tmpl b/templates/resources/instancev2.md.tmpl index 443be66b..a019d166 100644 --- a/templates/resources/instancev2.md.tmpl +++ b/templates/resources/instancev2.md.tmpl @@ -56,18 +56,6 @@ incoming traffic on ports 22, 80, and 443. Outgoing traffic is allowed on all po This example shows how to create a Windows instance with two users. The second user is added by using the userdata feature to automate the creation process. -userdata: -```userdata - -# Be sure to set the username and password on these two lines. Of course this is not a good -# security practice to include a password at command line. -$User = "SecondUser" -$Password = ConvertTo-SecureString "s3cR3tP@ssw0rd" -AsPlainText -Force -New-LocalUser $User -Password $Password -Add-LocalGroupMember -Group "Remote Desktop Users" -Member $User -Add-LocalGroupMember -Group "Administrators" -Member $User - -``` {{tffile "examples/resources/gcore_instancev2/windows-with-userdata.tf"}}