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

feat: Set resource ovh_cloud_project_region_storage_presign up to date #880

Merged
merged 1 commit into from
Mar 6, 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
25 changes: 22 additions & 3 deletions ovh/resource_cloud_project_region_storage_presign.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,27 @@ func resourceCloudProjectRegionStoragePresign() *schema.Resource {
ForceNew: true,
Description: "Name of the object to download or upload",
},
"version_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "Version ID of the object to download or delete",
},

// Computed
"url": {
Type: schema.TypeString,
Computed: true,
Description: "Presigned URL",
},
"signed_headers": {
Type: schema.TypeMap,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Computed: true,
Description: "Signed headers",
},
},
}
}
Expand All @@ -83,12 +97,17 @@ func resourceCloudProjectRegionStoragePresignCreate(d *schema.ResourceData, meta

endpoint := fmt.Sprintf("/cloud/project/%s/region/%s/storage/%s/presign", url.PathEscape(serviceName), url.PathEscape(regionName), url.PathEscape(name))
if err := config.OVHClient.Post(endpoint, opts, resp); err != nil {
return fmt.Errorf("Error calling post %s:\n\t %q", endpoint, err)
return fmt.Errorf("error calling post %s:\n\t %q", endpoint, err)
}

d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
err := d.Set("url", resp.URL)
if err != nil {
if err := d.Set("url", resp.URL); err != nil {
return err
}

if err := d.Set("signed_headers", resp.SignedHeaders); err != nil {
return err
}

return nil
}
13 changes: 8 additions & 5 deletions ovh/types_presigned_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ import (
)

type PresignedURL struct {
Method string `json:"method"`
URL string `json:"url"`
Method string `json:"method"`
URL string `json:"url"`
SignedHeaders map[string]string `json:"signedHeaders"`
}

type PresignedURLInput struct {
Expire int `json:"expire"`
Method string `json:"method"`
Object string `json:"object"`
Expire int `json:"expire"`
Method string `json:"method"`
Object string `json:"object"`
VersionId string `json:"versionId,omitempty"`
}

func (opts *PresignedURLInput) FromResource(d *schema.ResourceData) *PresignedURLInput {
opts.Expire = d.Get("expire").(int)
opts.Method = d.Get("method").(string)
opts.Object = d.Get("object").(string)
opts.VersionId = d.Get("version_id").(string)
return opts
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ The following arguments are supported:
- `method` - (Required) The method you want to use to interact with your
object. Can be either 'GET' or 'PUT'.
- `object` - (Required) The name of the object in your S3 bucket.
- `version_id` - Version ID of the object to download or delete


## Attributes Reference
Expand All @@ -50,3 +51,4 @@ The following attributes are exported:
* `method` - See Argument Reference above.
* `object` - See Argument Reference above.
* `url` - Computed URL result.
* `signed_headers` - Map of signed headers.