-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Object Storage] update: update missing code about action sub user
- Loading branch information
hoanglm
committed
Oct 29, 2024
1 parent
97c6db0
commit 782994e
Showing
10 changed files
with
494 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
fptcloud/object-storage/datasource_object_storage_lifecycle.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package fptcloud_object_storage | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
common "terraform-provider-fptcloud/commons" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func DataSourceBucketLifecycle() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceBucketLifecycle, | ||
Schema: map[string]*schema.Schema{ | ||
"vpc_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "The VPC ID", | ||
}, | ||
"bucket_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Name of the bucket to fetch policy for", | ||
}, | ||
"policy": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The bucket policy in JSON format", | ||
}, | ||
"region_name": { | ||
Type: schema.TypeString, | ||
Required: false, | ||
Default: "HCM-02", | ||
Optional: true, | ||
Description: "The region name of the bucket", | ||
}, | ||
"page_size": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "25", | ||
Description: "The number of items to return in each page", | ||
}, | ||
"page": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "1", | ||
Description: "The page number", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceBucketLifecycle(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
client := m.(*common.Client) | ||
service := NewObjectStorageService(client) | ||
|
||
bucketName := d.Get("bucket_name").(string) | ||
vpcId := d.Get("vpc_id").(string) | ||
s3ServiceDetail := getServiceEnableRegion(service, vpcId, d.Get("region_name").(string)) | ||
page := d.Get("page").(string) | ||
pageSize := d.Get("page_size").(string) | ||
|
||
lifeCycleResponse, err := service.GetBucketLifecycle(vpcId, s3ServiceDetail.S3ServiceId, bucketName, page, pageSize) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId(fmt.Sprintf("%s-%s", vpcId, bucketName)) | ||
if err := d.Set("policy", lifeCycleResponse.Rules); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return nil | ||
} |
142 changes: 142 additions & 0 deletions
142
fptcloud/object-storage/datasource_object_storage_static_website.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package fptcloud_object_storage | ||
|
||
import ( | ||
"context" | ||
common "terraform-provider-fptcloud/commons" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func DataSourceBucketStaticWebsite() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceBucketStaticWebsite, | ||
Schema: map[string]*schema.Schema{ | ||
"vpc_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "The VPC ID", | ||
}, | ||
"bucket_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Name of the bucket to fetch policy for", | ||
}, | ||
"region_name": { | ||
Type: schema.TypeString, | ||
Required: false, | ||
Default: "HCM-02", | ||
Optional: true, | ||
Description: "The region name of the bucket", | ||
}, | ||
"status": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "Status of the bucket website configuration", | ||
}, | ||
"request_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Request ID of the operation", | ||
}, | ||
"host_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Host ID of the operation", | ||
}, | ||
"http_status_code": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "HTTP status code of the operation", | ||
}, | ||
"http_headers": { | ||
Type: schema.TypeMap, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
Description: "HTTP headers of the response", | ||
}, | ||
"retry_attempts": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Number of retry attempts", | ||
}, | ||
"index_document": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Suffix for index document", | ||
}, | ||
"error_document": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Key for error document", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceBucketStaticWebsite(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
client := m.(*common.Client) | ||
service := NewObjectStorageService(client) | ||
|
||
bucketName := d.Get("bucket_name").(string) | ||
vpcId := d.Get("vpc_id").(string) | ||
s3ServiceDetail := getServiceEnableRegion(service, vpcId, d.Get("region_name").(string)) | ||
|
||
staticWebsiteResponse := service.GetBucketWebsite(vpcId, bucketName, s3ServiceDetail.S3ServiceId) | ||
if !staticWebsiteResponse.Status { | ||
return diag.Errorf("failed to get bucket policy for bucket %s", bucketName) | ||
} | ||
|
||
d.SetId(bucketName) | ||
|
||
// Set the computed values | ||
if err := d.Set("status", staticWebsiteResponse.Status); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
if staticWebsiteResponse.Config.ResponseMetadata.RequestID != "" { | ||
if err := d.Set("request_id", staticWebsiteResponse.Config.ResponseMetadata.RequestID); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
} | ||
|
||
if staticWebsiteResponse.Config.ResponseMetadata.HostID != "" { | ||
if err := d.Set("host_id", staticWebsiteResponse.Config.ResponseMetadata.HostID); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
} | ||
|
||
if err := d.Set("http_status_code", staticWebsiteResponse.Config.ResponseMetadata.HTTPStatusCode); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
headers := map[string]string{ | ||
"x-amz-request-id": staticWebsiteResponse.Config.ResponseMetadata.HTTPHeaders.XAmzRequestID, | ||
"content-type": staticWebsiteResponse.Config.ResponseMetadata.HTTPHeaders.ContentType, | ||
"content-length": staticWebsiteResponse.Config.ResponseMetadata.HTTPHeaders.ContentLength, | ||
"date": staticWebsiteResponse.Config.ResponseMetadata.HTTPHeaders.Date, | ||
} | ||
if err := d.Set("http_headers", headers); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
if err := d.Set("retry_attempts", staticWebsiteResponse.Config.ResponseMetadata.RetryAttempts); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
if staticWebsiteResponse.Config.IndexDocument.Suffix != "" { | ||
if err := d.Set("index_document", staticWebsiteResponse.Config.IndexDocument.Suffix); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
} | ||
|
||
if staticWebsiteResponse.Config.ErrorDocument.Key != "" { | ||
if err := d.Set("error_document", staticWebsiteResponse.Config.ErrorDocument.Key); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.