From 657a2f0d879e931bc7902c848ca58e98b190f035 Mon Sep 17 00:00:00 2001 From: Thibaut Di Prima Date: Wed, 9 Oct 2024 14:59:48 +0000 Subject: [PATCH] datasource & resource instance --- .cds/terraform-provider-ovh.yml | 1 + ovh/data_cloud_project_instance.go | 29 +++--- ovh/data_cloud_project_instances.go | 18 ++-- ovh/resource_cloud_project_instance.go | 97 +++++-------------- ovh/resource_cloud_project_instance_test.go | 66 +++++++++++-- ovh/types_cloud.go | 25 +++-- ovh/types_cloud_project_instance.go | 44 +-------- .../docs/d/cloud_project_instance.markdown | 11 ++- .../docs/d/cloud_project_instances.markdown | 12 ++- .../docs/r/cloud_project_instance.markdown | 17 ++-- 10 files changed, 148 insertions(+), 172 deletions(-) diff --git a/.cds/terraform-provider-ovh.yml b/.cds/terraform-provider-ovh.yml index 6de8832c3..080877735 100644 --- a/.cds/terraform-provider-ovh.yml +++ b/.cds/terraform-provider-ovh.yml @@ -576,6 +576,7 @@ workflow: one_at_a_time: true parameters: testargs: -run CloudProjectInstance + skipthispipeline: "{{.workflow.terraform-provider-ovh.pip.skipthistest.cloudproject}}" pipeline: terraform-provider-ovh-testacc when: - success diff --git a/ovh/data_cloud_project_instance.go b/ovh/data_cloud_project_instance.go index a1011e8ad..103fa15c0 100644 --- a/ovh/data_cloud_project_instance.go +++ b/ovh/data_cloud_project_instance.go @@ -17,7 +17,7 @@ func dataSourceCloudProjectInstance() *schema.Resource { Type: schema.TypeString, Required: true, DefaultFunc: schema.EnvDefaultFunc("OVH_CLOUD_PROJECT_SERVICE", nil), - Description: "Service name of the resource representing the id of the cloud project.", + Description: "Service name of the resource representing the id of the cloud project", }, "region": { Type: schema.TypeString, @@ -57,7 +57,7 @@ func dataSourceCloudProjectInstance() *schema.Resource { Schema: map[string]*schema.Schema{ "id": { Type: schema.TypeString, - Description: "Volume Id", + Description: "Volume id", Computed: true, }, }, @@ -75,12 +75,7 @@ func dataSourceCloudProjectInstance() *schema.Resource { }, "name": { Type: schema.TypeString, - Description: "Flavor name", - Computed: true, - }, - "id": { - Type: schema.TypeString, - Description: "Instance id", + Description: "Instance name", Computed: true, }, "image_id": { @@ -90,7 +85,7 @@ func dataSourceCloudProjectInstance() *schema.Resource { }, "ssh_key": { Type: schema.TypeString, - Description: "Instance task state", + Description: "SSH Key pair name", Computed: true, }, "task_state": { @@ -119,20 +114,19 @@ func dataSourceCloudProjectInstanceRead(d *schema.ResourceData, meta interface{} if err := config.OVHClient.Get(endpoint, &res); err != nil { return helpers.CheckDeleted(d, err, endpoint) } - log.Printf("[DEBUG] Read instance: %+v", res) - addresses := make([]map[string]interface{}, 0) - for i := range res.Addresses { + addresses := make([]map[string]interface{}, 0, len(res.Addresses)) + for _, addr := range res.Addresses { address := make(map[string]interface{}) - address["ip"] = res.Addresses[i].Ip - address["version"] = res.Addresses[i].Version + address["ip"] = addr.Ip + address["version"] = addr.Version addresses = append(addresses, address) } - attachedVolumes := make([]map[string]interface{}, 0) - for i := range res.AttachedVolumes { + attachedVolumes := make([]map[string]interface{}, 0, len(res.AttachedVolumes)) + for _, volume := range res.AttachedVolumes { attachedVolume := make(map[string]interface{}) - attachedVolume["id"] = res.AttachedVolumes[i].Id + attachedVolume["id"] = volume.Id attachedVolumes = append(attachedVolumes, attachedVolume) } @@ -145,6 +139,7 @@ func dataSourceCloudProjectInstanceRead(d *schema.ResourceData, meta interface{} d.Set("name", res.Name) d.Set("ssh_key", res.SshKey) d.Set("task_state", res.TaskState) + d.Set("attached_volumes", attachedVolumes) return nil } diff --git a/ovh/data_cloud_project_instances.go b/ovh/data_cloud_project_instances.go index 77df37377..9abc95544 100644 --- a/ovh/data_cloud_project_instances.go +++ b/ovh/data_cloud_project_instances.go @@ -19,7 +19,7 @@ func dataSourceCloudProjectInstances() *schema.Resource { Type: schema.TypeString, Required: true, DefaultFunc: schema.EnvDefaultFunc("OVH_CLOUD_PROJECT_SERVICE", nil), - Description: "Service name of the resource representing the id of the cloud project.", + Description: "Service name of the resource representing the id of the cloud project", }, "region": { Type: schema.TypeString, @@ -55,12 +55,12 @@ func dataSourceCloudProjectInstances() *schema.Resource { "attached_volumes": { Type: schema.TypeList, Computed: true, - Description: " Volumes attached to the instance", + Description: "Volumes attached to the instance", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "id": { Type: schema.TypeString, - Description: "Volume Id", + Description: "Volume id", Computed: true, }, }, @@ -78,7 +78,7 @@ func dataSourceCloudProjectInstances() *schema.Resource { }, "name": { Type: schema.TypeString, - Description: "Flavor name", + Description: "Instance name", Computed: true, }, "id": { @@ -93,7 +93,7 @@ func dataSourceCloudProjectInstances() *schema.Resource { }, "ssh_key": { Type: schema.TypeString, - Description: "Instance task state", + Description: "SSH Key pair name", Computed: true, }, "task_state": { @@ -124,10 +124,10 @@ func dataSourceCloudProjectInstancesRead(d *schema.ResourceData, meta interface{ return helpers.CheckDeleted(d, err, endpoint) } - instances := make([]map[string]interface{}, len(res)) - ids := make([]string, len(res)) - for i, instance := range res { - instances[i] = instance.ToMap() + instances := make([]map[string]interface{}, 0, len(res)) + ids := make([]string, 0, len(res)) + for _, instance := range res { + instances = append(instances, instance.ToMap()) ids = append(ids, instance.Id) } sort.Strings(ids) diff --git a/ovh/resource_cloud_project_instance.go b/ovh/resource_cloud_project_instance.go index c7bdc6192..834a0509b 100644 --- a/ovh/resource_cloud_project_instance.go +++ b/ovh/resource_cloud_project_instance.go @@ -5,12 +5,9 @@ import ( "fmt" "log" "net/url" - "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/ovh/go-ovh/ovh" "github.com/ovh/terraform-provider-ovh/ovh/helpers" ) @@ -25,7 +22,7 @@ func resourceCloudProjectInstance() *schema.Resource { Type: schema.TypeString, Required: true, DefaultFunc: schema.EnvDefaultFunc("OVH_CLOUD_PROJECT_SERVICE", nil), - Description: "Service name of the resource representing the id of the cloud project.", + Description: "Service name of the resource representing the id of the cloud project", ForceNew: true, }, "region": { @@ -134,12 +131,12 @@ func resourceCloudProjectInstance() *schema.Resource { Optional: true, ForceNew: true, MaxItems: 1, - Description: "Existing SSH Keypair", + Description: "Existing SSH Key pair", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, - Description: "SSH Keypair name", + Description: "SSH Key pair name", Required: true, }, }, @@ -150,17 +147,17 @@ func resourceCloudProjectInstance() *schema.Resource { Optional: true, ForceNew: true, MaxItems: 1, - Description: "Creatting SSH Keypair", + Description: "Add existing SSH Key pair into your Public Cloud project and link it to the instance", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, - Description: "SSH Keypair name", + Description: "SSH Key pair name", Required: true, }, "public_key": { Type: schema.TypeString, - Description: "Group id", + Description: "SSH Public Key", Required: true, }, }, @@ -211,12 +208,12 @@ func resourceCloudProjectInstance() *schema.Resource { "attached_volumes": { Type: schema.TypeSet, Computed: true, - Description: " Volumes attached to the instance", + Description: "Volumes attached to the instance", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "id": { Type: schema.TypeString, - Description: "Volume Id", + Description: "Volume id", Computed: true, }, }, @@ -258,79 +255,42 @@ func resourceCloudProjectInstanceCreate(ctx context.Context, d *schema.ResourceD params := new(CloudProjectInstanceCreateOpts) params.FromResource(d) - r := &CloudProjectOperation{} - endpoint := fmt.Sprintf("/cloud/project/%s/region/%s/instance", url.PathEscape(serviceName), url.PathEscape(region), ) + r := &CloudProjectOperationResponse{} if err := config.OVHClient.Post(endpoint, params, r); err != nil { return diag.Errorf("calling %s with params %v:\n\t %q", endpoint, params, err) } - err := waitForInstanceCreation(ctx, config.OVHClient, serviceName, r.Id) + instanceID, err := waitForCloudProjectOperation(ctx, config.OVHClient, serviceName, r.Id) if err != nil { return diag.Errorf("timeout instance creation: %s", err) } - endpointInstance := fmt.Sprintf("/cloud/project/%s/operation/%s", - url.PathEscape(serviceName), - url.PathEscape(r.Id), - ) - - err = config.OVHClient.GetWithContext(ctx, endpointInstance, r) - if err != nil { - return diag.Errorf("failed to get instance id: %s", err) - } - - d.SetId(r.SubOperations[0].ResourceId) + d.SetId(instanceID) d.Set("region", region) return resourceCloudProjectInstanceRead(ctx, d, meta) } -func waitForInstanceCreation(ctx context.Context, client *ovh.Client, serviceName, operationId string) error { - stateConf := &retry.StateChangeConf{ - Pending: []string{"null", "in-progress", "created", ""}, - Target: []string{"completed"}, - Refresh: func() (interface{}, string, error) { - res := &CloudProjectOperation{} - endpoint := fmt.Sprintf("/cloud/project/%s/operation/%s", - url.PathEscape(serviceName), - url.PathEscape(operationId), - ) - err := client.GetWithContext(ctx, endpoint, res) - if err != nil { - return res, "", err - } - return res, res.Status, nil - }, - Timeout: 360 * time.Second, - Delay: 10 * time.Second, - MinTimeout: 3 * time.Second, - } - - _, err := stateConf.WaitForStateContext(ctx) - return err -} - func resourceCloudProjectInstanceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) id := d.Id() region := d.Get("region").(string) serviceName := d.Get("service_name").(string) - r := &CloudProjectInstanceResponse{} - endpoint := fmt.Sprintf("/cloud/project/%s/region/%s/instance/%s", url.PathEscape(serviceName), url.PathEscape(region), url.PathEscape(id), ) + r := &CloudProjectInstanceResponse{} if err := config.OVHClient.Get(endpoint, r); err != nil { - return diag.Errorf("Error calling post %s:\n\t %q", endpoint, err) + return diag.Errorf("Error calling Get %s:\n\t %q", endpoint, err) } d.Set("flavor_id", r.FlavorId) @@ -338,27 +298,22 @@ func resourceCloudProjectInstanceRead(ctx context.Context, d *schema.ResourceDat d.Set("image_id", r.ImageId) d.Set("region", r.Region) d.Set("task_state", r.TaskState) - d.Set("name", d.Get("name").(string)) d.Set("id", r.Id) - addresses := make([]map[string]interface{}, 0) - if r.Addresses != nil { - for _, add := range r.Addresses { - address := make(map[string]interface{}) - address["ip"] = add.Ip - address["version"] = add.Version - addresses = append(addresses, address) - } + addresses := make([]map[string]interface{}, 0, len(r.Addresses)) + for _, add := range r.Addresses { + address := make(map[string]interface{}) + address["ip"] = add.Ip + address["version"] = add.Version + addresses = append(addresses, address) } d.Set("addresses", addresses) - attachedVolumes := make([]map[string]interface{}, 0) - if r.AttachedVolumes != nil { - for _, att := range r.AttachedVolumes { - attachedVolume := make(map[string]interface{}) - attachedVolume["id"] = att.Id - attachedVolumes = append(attachedVolumes, attachedVolume) - } + attachedVolumes := make([]map[string]interface{}, 0, len(r.AttachedVolumes)) + for _, att := range r.AttachedVolumes { + attachedVolume := make(map[string]interface{}) + attachedVolume["id"] = att.Id + attachedVolumes = append(attachedVolumes, attachedVolume) } d.Set("attached_volumes", attachedVolumes) @@ -380,11 +335,11 @@ func resourceCloudProjectInstanceDelete(ctx context.Context, d *schema.ResourceD ) if err := config.OVHClient.Delete(endpoint, nil); err != nil { - return diag.Errorf("Error calling post %s:\n\t %q", endpoint, err) + return diag.Errorf("Error calling Delete %s:\n\t %q", endpoint, err) } d.SetId("") - log.Printf("[DEBUG] Deleted Public Cloud %s Gateway %s", serviceName, id) + log.Printf("[DEBUG] Deleted Public Cloud %s Instance %s", serviceName, id) return nil } diff --git a/ovh/resource_cloud_project_instance_test.go b/ovh/resource_cloud_project_instance_test.go index 2bc8b76ed..51ae85103 100644 --- a/ovh/resource_cloud_project_instance_test.go +++ b/ovh/resource_cloud_project_instance_test.go @@ -2,23 +2,71 @@ package ovh import ( "fmt" + "net/url" "os" "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) +func getFlavorAndImage(project, region string) (string, string, error) { + client, err := clientDefault(&Config{}) + if err != nil { + return "", "", fmt.Errorf("error getting client: %w", err) + } + + type ResponseStruct struct { + ID string `json:"id"` + Type string `json:"type"` + OSType string `json:"osType"` + } + + endpoint := fmt.Sprintf("/cloud/project/%s/flavor?region=%s", url.PathEscape(project), url.QueryEscape(region)) + + var response []*ResponseStruct + if err := client.Get(endpoint, &response); err != nil { + return "", "", fmt.Errorf("failed to get flavors: %w", err) + } + + for _, flav := range response { + endpoint = fmt.Sprintf("/cloud/project/%s/image?region=%s&osType=%s&flavorType=%s", + url.PathEscape(project), + url.QueryEscape(region), + url.QueryEscape(flav.OSType), + url.QueryEscape(flav.Type), + ) + + var images []*ResponseStruct + if err := client.Get(endpoint, &images); err != nil { + return "", "", fmt.Errorf("failed to get images: %w", err) + } + + if len(images) > 0 { + return flav.ID, images[0].ID, nil + } + } + + return "", "", fmt.Errorf("found no flavor and image for project %s and region %s", project, region) +} + func TestAccCloudProjectInstance_basic(t *testing.T) { + serviceName := os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST") + region := os.Getenv("OVH_CLOUD_PROJECT_REGION_TEST") + flavor, image, err := getFlavorAndImage(serviceName, region) + if err != nil { + t.Fatalf("failed to retrieve a flavor and an image: %s", err) + } + var testCreateInstance = fmt.Sprintf(` resource "ovh_cloud_project_instance" "instance" { service_name = "%s" region = "%s" billing_period = "hourly" boot_from { - image_id = "46d79419-c5bb-4b78-90a5-75ea3d6f5767" + image_id = "%s" } flavor { - flavor_id = "21774833-28aa-442f-86b2-156343e3217f" + flavor_id = "%s" } name = "TestInstance" ssh_key { @@ -29,8 +77,10 @@ func TestAccCloudProjectInstance_basic(t *testing.T) { } } `, - os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST"), - os.Getenv("OVH_CLOUD_PROJECT_REGION_TEST"), + serviceName, + region, + image, + flavor, os.Getenv("OVH_CLOUD_PROJECT_SSH_NAME_TEST")) resource.Test(t, resource.TestCase{ @@ -44,10 +94,10 @@ func TestAccCloudProjectInstance_basic(t *testing.T) { Config: testCreateInstance, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("ovh_cloud_project_instance.instance", "id"), - resource.TestCheckResourceAttr("ovh_cloud_project_instance.instance", "flavor_name", "b3-8"), - resource.TestCheckResourceAttr("ovh_cloud_project_instance.instance", "flavor_id", "21774833-28aa-442f-86b2-156343e3217f"), - resource.TestCheckResourceAttr("ovh_cloud_project_instance.instance", "image_id", "46d79419-c5bb-4b78-90a5-75ea3d6f5767"), - resource.TestCheckResourceAttr("ovh_cloud_project_instance.instance", "region", os.Getenv("OVH_CLOUD_PROJECT_REGION_TEST")), + resource.TestCheckResourceAttr("ovh_cloud_project_instance.instance", "flavor_name", "b2-7"), + resource.TestCheckResourceAttr("ovh_cloud_project_instance.instance", "flavor_id", flavor), + resource.TestCheckResourceAttr("ovh_cloud_project_instance.instance", "image_id", image), + resource.TestCheckResourceAttr("ovh_cloud_project_instance.instance", "region", region), resource.TestCheckResourceAttr("ovh_cloud_project_instance.instance", "name", "TestInstance"), ), }, diff --git a/ovh/types_cloud.go b/ovh/types_cloud.go index 824ddc743..2e29ed776 100644 --- a/ovh/types_cloud.go +++ b/ovh/types_cloud.go @@ -55,15 +55,20 @@ type CloudProjectGatewayResponse struct { } type CloudProjectOperationResponse struct { - Id string `json:"id"` - Action string `json:"action"` - CreateAt string `json:"createdAt"` - StartedAt string `json:"startedAt"` - CompletedAt *string `json:"completedAt"` - Progress int `json:"progress"` - Regions []string `json:"regions"` - ResourceId *string `json:"resourceId"` - Status string `json:"status"` + Id string `json:"id"` + Action string `json:"action"` + CreateAt string `json:"createdAt"` + StartedAt string `json:"startedAt"` + CompletedAt *string `json:"completedAt"` + Progress int `json:"progress"` + Regions []string `json:"regions"` + ResourceId *string `json:"resourceId"` + Status string `json:"status"` + SubOperations []CloudProjectSubOperation `json:"subOperations"` +} + +type CloudProjectSubOperation struct { + ResourceId *string `json:"resourceId"` } func waitForCloudProjectOperation(ctx context.Context, c *ovh.Client, serviceName, operationId string) (string, error) { @@ -81,6 +86,8 @@ func waitForCloudProjectOperation(ctx context.Context, c *ovh.Client, serviceNam case "completed": if ro.ResourceId != nil { resourceID = *ro.ResourceId + } else if len(ro.SubOperations) > 0 && ro.SubOperations[0].ResourceId != nil { + resourceID = *ro.SubOperations[0].ResourceId } return nil default: diff --git a/ovh/types_cloud_project_instance.go b/ovh/types_cloud_project_instance.go index 759dd19ec..4160d216f 100644 --- a/ovh/types_cloud_project_instance.go +++ b/ovh/types_cloud_project_instance.go @@ -1,8 +1,6 @@ package ovh import ( - "log" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/ovh/terraform-provider-ovh/ovh/helpers" ) @@ -84,7 +82,7 @@ func (v CloudProjectInstanceResponse) ToMap() map[string]interface{} { obj["ssh_key"] = v.SshKey obj["task_state"] = v.TaskState - addresses := make([]map[string]interface{}, 0) + addresses := make([]map[string]interface{}, 0, len(v.Addresses)) for i := range v.Addresses { address := make(map[string]interface{}) address["ip"] = v.Addresses[i].Ip @@ -93,7 +91,7 @@ func (v CloudProjectInstanceResponse) ToMap() map[string]interface{} { } obj["addresses"] = addresses - attachedVolumes := make([]map[string]interface{}, 0) + attachedVolumes := make([]map[string]interface{}, 0, len(v.AttachedVolumes)) for i := range v.AttachedVolumes { attachedVolume := make(map[string]interface{}) attachedVolume["id"] = v.AttachedVolumes[i].Id @@ -105,40 +103,6 @@ func (v CloudProjectInstanceResponse) ToMap() map[string]interface{} { return obj } -type CloudProjectOperation struct { - Id string `json:"id"` - Status string `json:"status"` - SubOperations []SubOperation `json:"subOperations"` -} - -type SubOperation struct { - Id string `json:"id"` - ResourceId string `json:"resourceId"` - Status string `json:"status"` -} - -func (sb SubOperation) ToMap() map[string]interface{} { - obj := make(map[string]interface{}) - obj["id"] = sb.Id - obj["resourceId"] = sb.ResourceId - obj["status"] = sb.Status - - log.Printf("[DEBUG] tata suboperation %+v:", obj) - return obj -} - -func (o CloudProjectOperation) ToMap() map[string]interface{} { - obj := make(map[string]interface{}) - obj["id"] = o.Id - obj["status"] = o.Status - subOperations := make([]map[string]interface{}, len(o.SubOperations)) - for _, subOperation := range o.SubOperations { - subOperations = append(subOperations, subOperation.ToMap()) - } - obj["subOperations"] = subOperations - return obj -} - func (a Address) ToMap() map[string]interface{} { obj := make(map[string]interface{}) obj["ip"] = a.Ip @@ -157,7 +121,7 @@ type CloudProjectInstanceResponseList struct { Name string `json:"name"` } -func GetFlaorId(i interface{}) *Flavor { +func GetFlavorId(i interface{}) *Flavor { if i == nil { return nil } @@ -267,7 +231,7 @@ func GetNetwork(i interface{}) *Network { } func (cpir *CloudProjectInstanceCreateOpts) FromResource(d *schema.ResourceData) { - cpir.Flavor = GetFlaorId(d.Get("flavor")) + cpir.Flavor = GetFlavorId(d.Get("flavor")) cpir.AutoBackup = GetAutoBackup(d.Get("auto_backup")) cpir.BootFrom = GetBootFrom(d.Get("boot_from")) cpir.Group = GetGroup(d.Get("group")) diff --git a/website/docs/d/cloud_project_instance.markdown b/website/docs/d/cloud_project_instance.markdown index afac1b5d5..d05b31685 100644 --- a/website/docs/d/cloud_project_instance.markdown +++ b/website/docs/d/cloud_project_instance.markdown @@ -22,10 +22,10 @@ data "ovh_cloud_project_instance" "instance" { The following arguments are supported: -* `service_name` - (Required, Forces new resource) The id of the public cloud project. If omitted, - the `OVH_CLOUD_PROJECT_SERVICE` environment variable is used. -* `region` - (Required, Forces new resource) Instance region. -* `instance_id` - (Required, Forces new resource) Instance id +* `service_name` - (Required) The id of the public cloud project. If omitted, + the `OVH_CLOUD_PROJECT_SERVICE` environment variable is used +* `region` - (Required) Instance region +* `instance_id` - (Required) Instance id ## Attributes Reference @@ -35,10 +35,11 @@ The following attributes are exported: * `ip` - IP address * `version` - IP version * `attached_volumes` - Volumes attached to the instance - * `id` - Volume Id + * `id` - Volume id * `flavor_id` - Flavor id * `flavor_name` - Flavor name * `id` - Instance id +* `name` - Instance name * `image_id` - Image id * `task_state` - Instance task state * `ssh_key` - SSH Keypair diff --git a/website/docs/d/cloud_project_instances.markdown b/website/docs/d/cloud_project_instances.markdown index 41076c020..49a9ba61e 100644 --- a/website/docs/d/cloud_project_instances.markdown +++ b/website/docs/d/cloud_project_instances.markdown @@ -2,10 +2,11 @@ subcategory : "Cloud Project" --- -# ovh_cloud_project_instance +# ovh_cloud_project_instances + **This datasource uses a Beta API** -Use this data source to get the list of instance in a region of a public cloud project. +Use this data source to get the list of instances in a region of a public cloud project. ## Example Usage @@ -24,20 +25,21 @@ The following arguments are supported: * `service_name` - (Required) The id of the public cloud project. If omitted, the `OVH_CLOUD_PROJECT_SERVICE` environment variable is used. -* `region` - (Required, Forces new resource) Instance region. +* `region` - (Required) Instance region. ## Attributes Reference The following attributes are exported: -* `instances` - Instance +* `instances` - List of instances * `addresses` - Instance IP addresses * `ip` - IP address * `version` - IP version * `attached_volumes` - Volumes attached to the instance - * `id` - Volume Id + * `id` - Volume id * `flavor_id` - Flavor id * `flavor_name` - Flavor name * `id` - Instance id + * `name` - Instance name * `image_id` - Image id * `task_state` - Instance task state * `ssh_key` - SSH Keypair diff --git a/website/docs/r/cloud_project_instance.markdown b/website/docs/r/cloud_project_instance.markdown index 9092d6189..311285ed5 100644 --- a/website/docs/r/cloud_project_instance.markdown +++ b/website/docs/r/cloud_project_instance.markdown @@ -22,7 +22,7 @@ resource "ovh_cloud_project_instance" "instance" { flavor { flavor_id = "UUID" } - name = "sshkeyname" + name = "instance name" ssh_key { name = "sshname" } @@ -37,23 +37,23 @@ resource "ovh_cloud_project_instance" "instance" { The following arguments are supported: * `service_name` - (Required, Forces new resource) The id of the public cloud project. If omitted, - the `OVH_CLOUD_PROJECT_SERVICE` environment variable is used. -* `region` - (Required, Forces new resource) Instance region. + the `OVH_CLOUD_PROJECT_SERVICE` environment variable is used +* `region` - (Required, Forces new resource) Instance region * `billing_period` - (Required, Forces new resource) Billing period - hourly or monthly * `network` - (Required, Forces new resource) Create network interfaces * `public` - (Optional, Forces new resource) Set the new instance as public boolean * `flavor` - (Required, Forces new resource) Flavor information - * `flavor_id` - (Required, Forces new resource) Flavor ID + * `flavor_id` - (Required, Forces new resource) Flavor ID. Flavors can be retrieved using `GET /cloud/project/{serviceName}/flavor` * `boot_from` - (Required, Forces new resource) Boot the instance from an image or a volume - * `image_id` - (Mandatory only if volume_id not used, Forces new resource) Instance image id + * `image_id` - (Mandatory only if volume_id not used, Forces new resource) Instance image id. Images can be retrieved using `GET /cloud/project/{serviceName}/image` * `volume_id` - (Mandatory only if image_id not used, Forces new resource) Instance volume id * `group`- (Optional, Forces new resource) Start instance in group * `group_id` - (Optional, Forces new resource) Group id * `name` - (Required, Forces new resource) Instance name * `ssh_key` - (Mandatory only if ssh_key_create not used, Forces new resource) Existing SSH Keypair * `name` - (Optional, Forces new resource) SSH Keypair name -* `ssh_key_create` - (Mandatory only if ssh_key not used, Forces new resource) Unix cron pattern - * `name` - (Optional, Forces new resource) SSH Keypair name +* `ssh_key_create` - (Mandatory only if ssh_key not used, Forces new resource) Add existing SSH Key pair into your Public Cloud project and link it to the instance + * `name` - (Optional, Forces new resource) SSH Key pair name * `public_key` - (Optional, Forces new resource) SSH Public key * `user_data`- (Optional, Forces new resource) Configuration information or scripts to use upon launch * `auto_backup` - (Optional, Forces new resource) Create an autobackup workflow after instance start up. @@ -68,9 +68,10 @@ The following attributes are exported: * `ip` - IP address * `version` - IP version * `attached_volumes` - Volumes attached to the instance - * `id` - Volume Id + * `id` - Volume id * `flavor_id` - Flavor id * `flavor_name` - Flavor name * `id` - Instance id +* `name` - Instance name * `image_id` - Image id * `task_state` - Instance task state