Skip to content

feat: Add resource ovh_cloud_project_region #1044

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

Merged
merged 2 commits into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions docs/resources/cloud_project_region.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
subcategory : "Cloud Project"
---

# ovh_cloud_project_region (Resource)

## Example Usage

```terraform
resource "ovh_cloud_project_region" "region" {
service_name = "<public cloud project ID>"
region = "EU-WEST-LZ-LUX-A"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `region` (String) Region to add to your project
- `service_name` (String) Service name

### Read-Only

- `availability_zones` (List of String) Availability zones of the region
- `continent_code` (String) Region continent code
- `country_code` (String) Region country code
- `datacenter_location` (String) Location of the datacenter where the region is
- `ip_countries` (List of String) Allowed countries for failover ip
- `name` (String) Region name
- `region_name` (String) Region name
- `services` (Attributes List) Details about components status (see [below for nested schema](#nestedatt--services))
- `status` (String) Openstack region status
- `type` (String) Region type

<a id="nestedatt--services"></a>
### Nested Schema for `services`

Read-Only:

- `endpoint` (String) Endpoint URL
- `name` (String) Service name
- `status` (String) Service status
4 changes: 4 additions & 0 deletions examples/resources/ovh_cloud_project_region/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "ovh_cloud_project_region" "region" {
service_name = "<public cloud project ID>"
region = "EU-WEST-LZ-LUX-A"
}
1 change: 1 addition & 0 deletions ovh/provider_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ func (p *OvhProvider) Resources(_ context.Context) []func() resource.Resource {
NewCloudProjectLoadbalancerResource,
NewCloudProjectRancherResource,
NewCloudProjectRegionNetworkResource,
NewCloudProjectRegionResource,
NewCloudProjectSshKeyResource,
NewCloudProjectStorageResource,
NewCloudProjectVolumeBackupResource,
Expand Down
100 changes: 100 additions & 0 deletions ovh/resource_cloud_project_region.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package ovh

import (
"context"
"fmt"
"net/url"

"github.com/hashicorp/terraform-plugin-framework/resource"
)

var _ resource.ResourceWithConfigure = (*cloudProjectRegionResource)(nil)

func NewCloudProjectRegionResource() resource.Resource {
return &cloudProjectRegionResource{}
}

type cloudProjectRegionResource struct {
config *Config
}

func (r *cloudProjectRegionResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_cloud_project_region"
}

func (d *cloudProjectRegionResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
if req.ProviderData == nil {
return
}

config, ok := req.ProviderData.(*Config)
if !ok {
resp.Diagnostics.AddError(
"Unexpected Resource Configure Type",
fmt.Sprintf("Expected *Config, got: %T. Please report this issue to the provider developers.", req.ProviderData),
)
return
}

d.config = config
}

func (d *cloudProjectRegionResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = CloudProjectRegionResourceSchema(ctx)
}

func (r *cloudProjectRegionResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
var data, responseData CloudProjectRegionModel

// Read Terraform plan data into the model
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}

endpoint := "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/region"
if err := r.config.OVHClient.Post(endpoint, data.ToCreate(), &responseData); err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Error calling Post %s", endpoint),
err.Error(),
)
return
}

responseData.MergeWith(&data)

// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &responseData)...)
}

func (r *cloudProjectRegionResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var data, responseData CloudProjectRegionModel

// Read Terraform prior state data into the model
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}

endpoint := "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/region/" + url.PathEscape(data.Region.ValueString())

if err := r.config.OVHClient.Get(endpoint, &responseData); err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Error calling Get %s", endpoint),
err.Error(),
)
return
}

data.MergeWith(&responseData)

// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}

func (r *cloudProjectRegionResource) Update(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) {
resp.Diagnostics.AddError("update not implemented", "Resource cloud_project_region does not support update operations")
}

func (r *cloudProjectRegionResource) Delete(_ context.Context, _ resource.DeleteRequest, _ *resource.DeleteResponse) {
}
Loading