Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resource & data source instance #696

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Tiboau
Copy link
Contributor

@Tiboau Tiboau commented Jul 26, 2024

Description

Add resource and datasource for instance(s)

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Documentation update

How Has This Been Tested?

export OVH_CLOUD_PROJECT_SERVICE_TEST="AAA"
export OVH_CLOUD_PROJECT_REGION_TEST="XXX"
export OVH_CLOUD_PROJECT_IMAGE_ID_TEST="YYYY"
export OVH_CLOUD_PROJECT_FLAVOR_ID_TEST="ZZZZZ"
export OVH_CLOUD_PROJECT_SSH_NAME_TEST="UUUUU"

➜  terraform-provider-ovh git:(resource_cloud_project_instance.go) make testacc TESTARGS="-run TestAccCloudProjectInstance_basic"
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run TestAccCloudProjectInstance_basic -timeout 600m -p 10
?       github.com/ovh/terraform-provider-ovh   [no test files]
?       github.com/ovh/terraform-provider-ovh/ovh/helpers       [no test files]
?       github.com/ovh/terraform-provider-ovh/ovh/types [no test files]
=== RUN   TestAccCloudProjectInstance_basic
    provider_test.go:398: Read Cloud Project /cloud/project/bad3308a4b4d4dcba4d15d5b082d7225 -> status: 'ok', desc: 'Production'
--- PASS: TestAccCloudProjectInstance_basic (55.30s)
PASS
ok      github.com/ovh/terraform-provider-ovh/ovh       55.310s
testing: warning: no tests to run
PASS
ok      github.com/ovh/terraform-provider-ovh/ovh/helpers/hashcode      (cached) [no tests to run]
export OVH_CLOUD_PROJECT_SERVICE_TEST="AAA"
export OVH_CLOUD_PROJECT_REGION_TEST="XXX"
➜  terraform-provider-ovh git:(resource_cloud_project_instance.go) make testacc TESTARGS="-run TestAccDataSourceCloudProjecInstances_basic"
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run TestAccDataSourceCloudProjecInstances_basic -timeout 600m -p 10
?       github.com/ovh/terraform-provider-ovh   [no test files]
?       github.com/ovh/terraform-provider-ovh/ovh/helpers       [no test files]
?       github.com/ovh/terraform-provider-ovh/ovh/types [no test files]
=== RUN   TestAccDataSourceCloudProjecInstances_basic
    provider_test.go:398: Read Cloud Project /cloud/project/bad3308a4b4d4dcba4d15d5b082d7225 -> status: 'ok', desc: 'Production'
--- PASS: TestAccDataSourceCloudProjecInstances_basic (6.78s)
PASS
ok      github.com/ovh/terraform-provider-ovh/ovh       6.788s
testing: warning: no tests to run
PASS
ok      github.com/ovh/terraform-provider-ovh/ovh/helpers/hashcode      (cached) [no tests to run]
export OVH_CLOUD_PROJECT_SERVICE_TEST="AAA"
export OVH_CLOUD_PROJECT_REGION_TEST="XXX"
export OVH_CLOUD_PROJECT_INSTANCE_TEST="YYYY"
➜  terraform-provider-ovh git:(resource_cloud_project_instance.go) make testacc TESTARGS="-run TestAccDataSourceCloudProjecInstances_basic"
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run TestAccDataSourceCloudProjecInstancesbasic -timeout 600m -p 10
?       github.com/ovh/terraform-provider-ovh   [no test files]
?       github.com/ovh/terraform-provider-ovh/ovh/helpers       [no test files]
?       github.com/ovh/terraform-provider-ovh/ovh/types [no test files]
testing: warning: no tests to run
PASS
ok      github.com/ovh/terraform-provider-ovh/ovh       0.011s [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/ovh/terraform-provider-ovh/ovh/helpers/hashcode      0.003s [no tests to run]

Test Configuration:

  • Terraform version: terraform version: Terraform vx.y.z
  • Existing HCL configuration you used:
resource "ovh_cloud_project_instance" "instance" {
    region = "BHS5"
    billing_period = "hourly"
    boot_from {
        image_id = "7ec6515e-b390-41f8-a26a-cca7e223ca2d"
    }
    flavor {
        flavor_id = "ac6f8199-3595-446f-bfc7-c80cdfcf9cbe"
    }
    name = "haproxy"
    ssh_key {
        name = "ovh_cloud"
    }
    network {
        public = true
    }   
}

data "ovh_cloud_project_instances" "instances" {
   region = ovh_cloud_project_instance.instance.region
}

data "ovh_cloud_project_instance" "desc" {
   region = ovh_cloud_project_instance.instance.region
   instance_id = ovh_cloud_project_instance.instance.id
}

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or issues
  • I have added acceptance tests that prove my fix is effective or that my feature works
  • New and existing acceptance tests pass locally with my changes
  • I ran succesfully go mod vendor if I added or modify go.mod file

Type: schema.TypeString,
Description: "Instance id",
Required: true,
ForceNew: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess ForceNew's are not really needed here

},
// computed
"addresses": {
Type: schema.TypeList,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Type: schema.TypeList,
Type: schema.TypeSet,

no ?

Description: " Volumes attached to the instance",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"ip": {
"id": {

},
},
"attached_volumes": {
Type: schema.TypeList,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Type: schema.TypeList,
Type: schema.TypeSet,

serviceName := d.Get("service_name").(string)
region := d.Get("region").(string)
instanceId := d.Get("instance_id").(string)
log.Printf("[DEBUG] SCROUTCH")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.Printf("[DEBUG] SCROUTCH")

d.Set("region", r.Region)
d.Set("task_state", r.TaskState)
d.Set("name", d.Get("name").(string))
// d.Set("name", r.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// d.Set("name", r.Name)

Steps: []resource.TestStep{
{
Config: testCreateLoadBalancerLogSubscription,
Check: resource.ComposeTestCheckFunc(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check values of several field


## Example Usage

To get information of an instance:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To get information of an instance:
To list your instances:


# ovh_cloud_project_instance
**This datasource uses a Beta API**
Use this data source to get the list instance in a region of a public cloud project.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Use this data source to get the list instance in a region of a public cloud project.
Use this data source to get the list of instance in a region of a public cloud project.


The following arguments are supported:

* `service_name` - (Required, Forces new resource) The id of the public cloud project. If omitted,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `service_name` - (Required, Forces new resource) The id of the public cloud project. If omitted,
* `service_name` - (Required) The id of the public cloud project. If omitted,

not sure this makes sense in a datasource

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants