From 4885c6a455b44c2de3322b9c5d95c914cc01176b Mon Sep 17 00:00:00 2001
From: s2thudry <72788606+s2thudry@users.noreply.github.com>
Date: Thu, 20 Jun 2024 13:42:36 +0200
Subject: [PATCH] Fix Azure and GCP remote tier creation and add support for
tier options (#566)
---
docs/resources/ilm_tier.md | 4 +-
minio/resource_minio_ilm_tier.go | 89 +++++++++++++++++++++++++++-----
2 files changed, 78 insertions(+), 15 deletions(-)
diff --git a/docs/resources/ilm_tier.md b/docs/resources/ilm_tier.md
index f520c3df..4828ab00 100644
--- a/docs/resources/ilm_tier.md
+++ b/docs/resources/ilm_tier.md
@@ -42,7 +42,8 @@ description: |-
Optional:
- `account_key` (String, Sensitive)
-- `container` (String)
+- `account_name` (String)
+- `storage_class` (String)
@@ -51,6 +52,7 @@ Optional:
Optional:
- `credentials` (String, Sensitive)
+- `storage_class` (String)
diff --git a/minio/resource_minio_ilm_tier.go b/minio/resource_minio_ilm_tier.go
index 2da8caae..33b6d0b9 100644
--- a/minio/resource_minio_ilm_tier.go
+++ b/minio/resource_minio_ilm_tier.go
@@ -42,10 +42,11 @@ func resourceMinioILMTier() *schema.Resource {
ValidateFunc: validation.StringInSlice([]string{"s3", "minio", "gcs", "azure"}, false),
},
"endpoint": {
- Type: schema.TypeString,
- Optional: true,
- ForceNew: true,
- Default: "",
+ Type: schema.TypeString,
+ Optional: true,
+ ForceNew: true,
+ Sensitive: false,
+ Default: "",
},
"region": {
Type: schema.TypeString,
@@ -117,10 +118,9 @@ func resourceMinioILMTier() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
- "container": {
+ "account_name": {
Type: schema.TypeString,
Optional: true,
- ForceNew: true,
},
"account_key": {
Type: schema.TypeString,
@@ -133,6 +133,11 @@ func resourceMinioILMTier() *schema.Resource {
return old == "REDACTED"
},
},
+ "storage_class": {
+ Type: schema.TypeString,
+ Optional: true,
+ ForceNew: true,
+ },
},
},
},
@@ -153,6 +158,11 @@ func resourceMinioILMTier() *schema.Resource {
return old == "REDACTED"
},
},
+ "storage_class": {
+ Type: schema.TypeString,
+ Optional: true,
+ ForceNew: true,
+ },
},
},
},
@@ -168,32 +178,80 @@ func minioCreateILMTier(ctx context.Context, d *schema.ResourceData, meta interf
d.SetId(name)
switch d.Get("type").(string) {
case madmin.S3.String():
+ s3Config := d.Get("s3_config").([]interface{})[0].(map[string]interface{})
+ var s3Options []madmin.S3Options
+ if d.Get("prefix").(string) != "" {
+ s3Options = append(s3Options, madmin.S3Prefix(d.Get("prefix").(string)))
+ }
+ if d.Get("region").(string) != "" {
+ s3Options = append(s3Options, madmin.S3Region(d.Get("region").(string)))
+ }
+ if _, ok := s3Config["storage_class"]; ok {
+ s3Options = append(s3Options, madmin.S3StorageClass(s3Config["storage_class"].(string)))
+ }
tierConf, err = madmin.NewTierS3(
name,
- d.Get("access_key").(string),
- d.Get("secret_key").(string),
+ s3Config["access_key"].(string),
+ s3Config["secret_key"].(string),
d.Get("bucket").(string),
+ s3Options...,
)
case madmin.MinIO.String():
minioConfig := d.Get("minio_config").([]interface{})[0].(map[string]interface{})
+ var minioOptions []madmin.MinIOOptions
+ if d.Get("prefix").(string) != "" {
+ minioOptions = append(minioOptions, madmin.MinIOPrefix(d.Get("prefix").(string)))
+ }
+ if d.Get("region").(string) != "" {
+ minioOptions = append(minioOptions, madmin.MinIORegion(d.Get("region").(string)))
+ }
+
tierConf, err = madmin.NewTierMinIO(
name,
d.Get("endpoint").(string),
minioConfig["access_key"].(string),
minioConfig["secret_key"].(string),
d.Get("bucket").(string),
+ minioOptions...,
)
case madmin.GCS.String():
+ gcsConfig := d.Get("gcs_config").([]interface{})[0].(map[string]interface{})
+ var gcsOptions []madmin.GCSOptions
+ if d.Get("prefix").(string) != "" {
+ gcsOptions = append(gcsOptions, madmin.GCSPrefix(d.Get("prefix").(string)))
+ }
+ if d.Get("region").(string) != "" {
+ gcsOptions = append(gcsOptions, madmin.GCSPrefix(d.Get("region").(string)))
+ }
+ if _, ok := gcsConfig["storage_class"]; ok {
+ gcsOptions = append(gcsOptions, madmin.GCSStorageClass(gcsConfig["storage_class"].(string)))
+ }
tierConf, err = madmin.NewTierGCS(
name,
- d.Get("credentials").([]byte),
+ []byte(gcsConfig["credentials"].(string)),
d.Get("bucket").(string),
+ gcsOptions...,
)
case madmin.Azure.String():
+ azureConfig := d.Get("azure_config").([]interface{})[0].(map[string]interface{})
+ var azureOptions []madmin.AzureOptions
+ if d.Get("endpoint").(string) != "" {
+ azureOptions = append(azureOptions, madmin.AzureEndpoint(d.Get("endpoint").(string)))
+ }
+ if d.Get("prefix").(string) != "" {
+ azureOptions = append(azureOptions, madmin.AzurePrefix(d.Get("prefix").(string)))
+ }
+ if d.Get("region").(string) != "" {
+ azureOptions = append(azureOptions, madmin.AzureRegion(d.Get("region").(string)))
+ }
+ if _, ok := azureConfig["storage_class"]; ok {
+ azureOptions = append(azureOptions, madmin.AzureStorageClass(azureConfig["storage_class"].(string)))
+ }
tierConf, err = madmin.NewTierAzure(name,
- d.Get("account_name").(string),
- d.Get("account_key").(string),
+ azureConfig["account_name"].(string),
+ azureConfig["account_key"].(string),
d.Get("bucket").(string),
+ azureOptions...,
)
}
if err != nil {
@@ -220,6 +278,7 @@ func minioReadILMTier(ctx context.Context, d *schema.ResourceData, meta interfac
return nil
}
log.Printf("[DEBUG] Tier [%s] exists!", name)
+ d.SetId(tier.Name)
if err := d.Set("type", tier.Type.String()); err != nil {
return diag.FromErr(err)
}
@@ -249,15 +308,17 @@ func minioReadILMTier(ctx context.Context, d *schema.ResourceData, meta interfac
}
case madmin.GCS:
gcsConfig := []map[string]string{{
- "credentials": tier.GCS.Creds,
+ "credentials": tier.GCS.Creds,
+ "storage_class": tier.GCS.StorageClass,
}}
if err := d.Set("gcs_config", gcsConfig); err != nil {
return diag.FromErr(err)
}
case madmin.Azure:
azureConfig := []map[string]string{{
- "container": tier.Azure.AccountName,
- "account_key": tier.Azure.AccountKey,
+ "account_name": tier.Azure.AccountName,
+ "account_key": tier.Azure.AccountKey,
+ "storage_class": tier.Azure.StorageClass,
}}
if err := d.Set("azure_config", azureConfig); err != nil {
return diag.FromErr(err)