IBM-Cloud / terraform-provider-ibm

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs
Mozilla Public License 2.0
341 stars 670 forks source link

VPC Feature Request: Implement creation of dataVolumes in the instance create routine #881

Closed dprosper closed 3 years ago

dprosper commented 4 years ago

The ibmcloud CLI to create a virtual server instance in VPC allows you to create the data volume during the create instance.

$ ibmcloud is instance-create --help
NAME:
    instance-create, inc - Create a server instance

USAGE:
    C:\Program Files\IBM\Cloud\bin\ibmcloud.exe is instance-create INSTANCE_NAME VPC ZONE_NAME PROFILE_NAME SUBNET --image-id IMAGE_ID [--boot-volume BOOT_VOLUME_JSON | @BOOT_VOLUME_JSON_FILE] [--volume-attach VOLUME_ATTACH_JSON | @VOLUME_ATTACH_JSON_FILE] [--key-ids IDS] [--user-data DATA] [--network-interface NETWORK_INTERFACE_JSON | @NETWORK_INTERFACE_JSON_FILE] [--security-group-ids SECURITY_GROUP_IDS] [--resource-group-id RESOURCE_GROUP_ID | --resource-group-name RESOURCE_GROUP_NAME] [--json]
    INSTANCE_NAME: Name of the instance.
    VPC:           ID of the vpc.
    ZONE_NAME:     Name of the zone.
    PROFILE_NAME:  Name of the profile.
    SUBNET:        ID of the subnet.

OPTIONS:
   --boot-volume value          BOOT_VOLUME_JSON|@BOOT_VOLUME_JSON_FILE, boot volume attachment in json or json file
   --volume-attach value        VOLUME_ATTACH_JSON|@VOLUME_ATTACH_JSON_FILE, volume attachment in json or json file
   --image-id value             ID of the image.
   --security-group-ids value   Comma separated security group IDs for primary network interface.
   --key-ids value              Comma separated IDs of SSH keys.
   --user-data value            data|@data-file. User data to transfer to the server instance
   --network-interface value    NETWORK_INTERFACE_JSON|@NETWORK_INTERFACE_JSON_FILE, network interface attachment in json or json file
   --resource-group-id value    ID of the resource group. This option is mutually exclusive with --resource-group-name
   --resource-group-name value  Name of the resource group. This option is mutually exclusive with --resource-group-id
   --json                       Format output in JSON

The IBM Terraform provider does it in three (3) steps:

  1. Create the volume
  2. Create the instance
  3. Attach the volume to the instance.

Issue #871 uncovered a problem that happens when multiple VSIs are getting created at the same time and the attach volume is happening when the VSI is not in a running state.

Although this can be fixed by confirming the VSI is running, this is not an ideal situation as this might still cause problems when cloud-init is added to the picture.

Ideally, the Terraform process should match the ibmcloud CLI process and allow the creation of the dataVolumes to occur during the VSI creation process (i.e. a single step as opposed to the 3 step process above). The RIAS API support this:

https://cloud.ibm.com/apidocs/vpc-on-classic#create-an-instance

ujjwal-ibm commented 3 years ago

As per https://github.com/IBM-Cloud/terraform-provider-ibm/pull/2672

We are supporting volume attachments as a separate resource(which supports both creation of a new volume, attaching existing volumes), keeping the existing feature which supports attaching an existing volume.

resource "ibm_is_instance_volume_attachment" "att1" {
   instance                            = ibm_is_instance.instance5.id
   volume                              = ibm_is_volume.vol5.id
   name                                = "vol-att-1"
   delete_volume_on_attachment_delete  = false
   delete_volume_on_instance_delete    = false
 }
dprosper commented 3 years ago

@ujjwal-ibm This is not clear to me, does this mean now I can do what I requested, i.e. create an instance AND a volume just like the CLI?

ujjwal-ibm commented 3 years ago

@dprosper no. We had some limitation wrt terraform and the backend sdk, so we couldn't support it the way cli does.

As per the new support:

  1. Create an instance (with/without existing volumes)
  2. Create a volume attachment on that resource (new/existing volumes)
dprosper commented 3 years ago

ok so I guess this can be close as can-t-fix. thx

kavya498 commented 3 years ago

Closing this issue.. Thanks