-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #296 from lpatte/PUD-1393/6-1401/2/3_Kafka-Opensea…
…rch-lifecycle Kafka and opensearch lifecycle
- Loading branch information
Showing
87 changed files
with
4,169 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package ovh | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/url" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/ovh/terraform-provider-ovh/ovh/helpers" | ||
) | ||
|
||
func dataSourceCloudProjectDatabaseKafkaAcl() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceCloudProjectDatabaseKafkaAclRead, | ||
Schema: map[string]*schema.Schema{ | ||
"service_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: schema.EnvDefaultFunc("OVH_CLOUD_PROJECT_SERVICE", nil), | ||
}, | ||
"cluster_id": { | ||
Type: schema.TypeString, | ||
Description: "Id of the database cluster", | ||
Required: true, | ||
}, | ||
"id": { | ||
Type: schema.TypeString, | ||
Description: "Acl ID", | ||
Required: true, | ||
}, | ||
|
||
// Computed | ||
"permission": { | ||
Type: schema.TypeString, | ||
Description: "Permission to give to this username on this topic", | ||
Computed: true, | ||
}, | ||
"topic": { | ||
Type: schema.TypeString, | ||
Description: "Topic affected by this acl", | ||
Computed: true, | ||
}, | ||
"username": { | ||
Type: schema.TypeString, | ||
Description: "Username affected by this acl", | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceCloudProjectDatabaseKafkaAclRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
serviceName := d.Get("service_name").(string) | ||
clusterId := d.Get("cluster_id").(string) | ||
id := d.Get("id").(string) | ||
|
||
endpoint := fmt.Sprintf("/cloud/project/%s/database/kafka/%s/acl/%s", | ||
url.PathEscape(serviceName), | ||
url.PathEscape(clusterId), | ||
url.PathEscape(id), | ||
) | ||
res := &CloudProjectDatabaseKafkaAclResponse{} | ||
|
||
log.Printf("[DEBUG] Will read acl %s from cluster %s from project %s", id, clusterId, serviceName) | ||
if err := config.OVHClient.Get(endpoint, res); err != nil { | ||
return helpers.CheckDeleted(d, err, endpoint) | ||
} | ||
|
||
for k, v := range res.ToMap() { | ||
if k != "id" { | ||
d.Set(k, v) | ||
} else { | ||
d.SetId(fmt.Sprint(v)) | ||
} | ||
} | ||
|
||
log.Printf("[DEBUG] Read acl %+v", res) | ||
return nil | ||
} |
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,90 @@ | ||
package ovh | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
const testAccCloudProjectDatabaseKafkaAclDatasourceConfig_Basic = ` | ||
resource "ovh_cloud_project_database" "db" { | ||
service_name = "%s" | ||
description = "%s" | ||
engine = "kafka" | ||
version = "%s" | ||
plan = "business" | ||
nodes { | ||
region = "%s" | ||
} | ||
nodes { | ||
region = "%s" | ||
} | ||
nodes { | ||
region = "%s" | ||
} | ||
flavor = "%s" | ||
} | ||
resource "ovh_cloud_project_database_kafka_acl" "acl" { | ||
service_name = ovh_cloud_project_database.db.service_name | ||
cluster_id = ovh_cloud_project_database.db.id | ||
permission = "%s" | ||
topic = "%s" | ||
username = "%s" | ||
} | ||
data "ovh_cloud_project_database_kafka_acl" "acl" { | ||
service_name = ovh_cloud_project_database_kafka_acl.acl.service_name | ||
cluster_id = ovh_cloud_project_database_kafka_acl.acl.cluster_id | ||
id = ovh_cloud_project_database_kafka_acl.acl.id | ||
} | ||
` | ||
|
||
func TestAccCloudProjectDatabaseKafkaAclDataSource_basic(t *testing.T) { | ||
serviceName := os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST") | ||
version := os.Getenv("OVH_CLOUD_PROJECT_DATABASE_KAFKA_VERSION_TEST") | ||
if version == "" { | ||
version = os.Getenv("OVH_CLOUD_PROJECT_DATABASE_VERSION_TEST") | ||
} | ||
region := os.Getenv("OVH_CLOUD_PROJECT_DATABASE_REGION_TEST") | ||
flavor := os.Getenv("OVH_CLOUD_PROJECT_DATABASE_FLAVOR_TEST") | ||
description := acctest.RandomWithPrefix(test_prefix) | ||
permission := "read" | ||
topic := "myTopic" | ||
username := "johnDoe" | ||
|
||
config := fmt.Sprintf( | ||
testAccCloudProjectDatabaseKafkaAclDatasourceConfig_Basic, | ||
serviceName, | ||
description, | ||
version, | ||
region, | ||
region, | ||
region, | ||
flavor, | ||
permission, | ||
topic, | ||
username, | ||
) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheckCloudDatabaseNoEngine(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
"data.ovh_cloud_project_database_kafka_acl.acl", "permission", permission), | ||
resource.TestCheckResourceAttr( | ||
"data.ovh_cloud_project_database_kafka_acl.acl", "topic", topic), | ||
resource.TestCheckResourceAttr( | ||
"data.ovh_cloud_project_database_kafka_acl.acl", "username", username), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
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,62 @@ | ||
package ovh | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/url" | ||
"sort" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/ovh/terraform-provider-ovh/ovh/helpers" | ||
"github.com/ovh/terraform-provider-ovh/ovh/helpers/hashcode" | ||
) | ||
|
||
func dataSourceCloudProjectDatabaseKafkaAcls() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceCloudProjectDatabaseKafkaAclsRead, | ||
Schema: map[string]*schema.Schema{ | ||
"service_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: schema.EnvDefaultFunc("OVH_CLOUD_PROJECT_SERVICE", nil), | ||
}, | ||
"cluster_id": { | ||
Type: schema.TypeString, | ||
Description: "Id of the database cluster", | ||
Required: true, | ||
}, | ||
|
||
// Computed | ||
"acl_ids": { | ||
Type: schema.TypeList, | ||
Description: "List of acl ids", | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceCloudProjectDatabaseKafkaAclsRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
serviceName := d.Get("service_name").(string) | ||
clusterId := d.Get("cluster_id").(string) | ||
|
||
endpoint := fmt.Sprintf("/cloud/project/%s/database/kafka/%s/acl", | ||
url.PathEscape(serviceName), | ||
url.PathEscape(clusterId), | ||
) | ||
res := make([]string, 0) | ||
|
||
log.Printf("[DEBUG] Will read acls from cluster %s from project %s", clusterId, serviceName) | ||
if err := config.OVHClient.Get(endpoint, &res); err != nil { | ||
return helpers.CheckDeleted(d, err, endpoint) | ||
} | ||
|
||
// sort.Strings sorts in place, returns nothing | ||
sort.Strings(res) | ||
|
||
d.SetId(hashcode.Strings(res)) | ||
d.Set("acl_ids", res) | ||
return nil | ||
} |
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,87 @@ | ||
package ovh | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
const testAccCloudProjectDatabaseKafkaAclsDatasourceConfig_Basic = ` | ||
resource "ovh_cloud_project_database" "db" { | ||
service_name = "%s" | ||
description = "%s" | ||
engine = "kafka" | ||
version = "%s" | ||
plan = "business" | ||
nodes { | ||
region = "%s" | ||
} | ||
nodes { | ||
region = "%s" | ||
} | ||
nodes { | ||
region = "%s" | ||
} | ||
flavor = "%s" | ||
} | ||
resource "ovh_cloud_project_database_kafka_acl" "acl" { | ||
service_name = ovh_cloud_project_database.db.service_name | ||
cluster_id = ovh_cloud_project_database.db.id | ||
permission = "%s" | ||
topic = "%s" | ||
username = "%s" | ||
} | ||
data "ovh_cloud_project_database_kafka_acls" "acls" { | ||
service_name = ovh_cloud_project_database_kafka_acl.acl.service_name | ||
cluster_id = ovh_cloud_project_database_kafka_acl.acl.cluster_id | ||
} | ||
` | ||
|
||
func TestAccCloudProjectDatabaseKafkaAclsDataSource_basic(t *testing.T) { | ||
serviceName := os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST") | ||
version := os.Getenv("OVH_CLOUD_PROJECT_DATABASE_KAFKA_VERSION_TEST") | ||
if version == "" { | ||
version = os.Getenv("OVH_CLOUD_PROJECT_DATABASE_VERSION_TEST") | ||
} | ||
region := os.Getenv("OVH_CLOUD_PROJECT_DATABASE_REGION_TEST") | ||
flavor := os.Getenv("OVH_CLOUD_PROJECT_DATABASE_FLAVOR_TEST") | ||
description := acctest.RandomWithPrefix(test_prefix) | ||
permission := "read" | ||
topic := "myTopic" | ||
username := "johnDoe" | ||
|
||
config := fmt.Sprintf( | ||
testAccCloudProjectDatabaseKafkaAclsDatasourceConfig_Basic, | ||
serviceName, | ||
description, | ||
version, | ||
region, | ||
region, | ||
region, | ||
flavor, | ||
permission, | ||
topic, | ||
username, | ||
) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheckCloudDatabaseNoEngine(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet( | ||
"data.ovh_cloud_project_database_kafka_acls.acls", | ||
"acl_ids.#", | ||
), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
Oops, something went wrong.