-
Notifications
You must be signed in to change notification settings - Fork 153
Add Database kafka schema registry #449
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
scraly
merged 12 commits into
ovh:master
from
BellionBastien:dev/bbellion/add-database-kafka-schema-registry
Aug 18, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e037e01
Add Database kafka schema registry
BellionBastien 7a82723
Update ovh/resource_cloud_project_database_kafka_schemaregistryacl.go
BellionBastien fbda21d
Update website/docs/r/cloud_project_database_kafka_schemaregistryacl.…
BellionBastien 0138f90
Update website/docs/r/cloud_project_database_kafka_schemaregistryacl.…
BellionBastien b60b605
Update ovh/data_cloud_project_database_kafka_schemaregistryacl.go
BellionBastien a237cf3
Update ovh/resource_cloud_project_database_kafka_schemaregistryacl.go
BellionBastien a4ad2ff
Update ovh/data_cloud_project_database_kafka_schemaregistryacl.go
BellionBastien ed3c8e1
Update ovh/data_cloud_project_database_kafka_schemaregistryacl.go
BellionBastien 9a3e253
Update ovh/resource_cloud_project_database_kafka_schemaregistryacl.go
BellionBastien 424f1de
Update ovh/data_cloud_project_database_kafka_schemaregistryacls.go
BellionBastien 41e2165
Update ovh/data_cloud_project_database_kafka_schemaregistryacl.go
BellionBastien 0711c98
Update ovh/data_cloud_project_database_kafka_schemaregistryacl.go
BellionBastien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
ovh/data_cloud_project_database_kafka_schemaregistryacl.go
This file contains hidden or 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,82 @@ | ||
package ovh | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"net/url" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/ovh/terraform-provider-ovh/ovh/helpers" | ||
) | ||
|
||
func dataSourceCloudProjectDatabaseKafkaSchemaRegistryAcl() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceCloudProjectDatabaseKafkaSchemaregistryaclRead, | ||
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: "Shema registry ACL ID", | ||
Required: true, | ||
}, | ||
|
||
// Computed | ||
"permission": { | ||
Type: schema.TypeString, | ||
Description: "Permission to give to this username on this resource", | ||
Computed: true, | ||
}, | ||
"resource": { | ||
Type: schema.TypeString, | ||
Description: "Resource affected by this ACL", | ||
Computed: true, | ||
}, | ||
"username": { | ||
Type: schema.TypeString, | ||
Description: "Username affected by this ACL", | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceCloudProjectDatabaseKafkaSchemaregistryaclRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
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/schemaRegistryAcl/%s", | ||
url.PathEscape(serviceName), | ||
url.PathEscape(clusterID), | ||
url.PathEscape(id), | ||
) | ||
res := &CloudProjectDatabaseKafkaAclResponse{} | ||
|
||
log.Printf("[DEBUG] Will read schema registry ACL %s from cluster %s from project %s", id, clusterID, serviceName) | ||
if err := config.OVHClient.Get(endpoint, res); err != nil { | ||
return diag.FromErr(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 | ||
} |
64 changes: 64 additions & 0 deletions
64
ovh/data_cloud_project_database_kafka_schemaregistryacls.go
This file contains hidden or 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,64 @@ | ||
package ovh | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"net/url" | ||
"sort" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"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 dataSourceCloudProjectDatabaseKafkaSchemaRegistryAcls() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceCloudProjectDatabaseKafkaSchemaregistryclsRead, | ||
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 schema registry acl ids", | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceCloudProjectDatabaseKafkaSchemaregistryclsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
config := meta.(*Config) | ||
serviceName := d.Get("service_name").(string) | ||
clusterId := d.Get("cluster_id").(string) | ||
|
||
endpoint := fmt.Sprintf("/cloud/project/%s/database/kafka/%s/schemaRegistryAcl", | ||
url.PathEscape(serviceName), | ||
url.PathEscape(clusterId), | ||
) | ||
res := make([]string, 0) | ||
|
||
log.Printf("[DEBUG] Will read schema registry ACLs from cluster %s from project %s", clusterId, serviceName) | ||
if err := config.OVHClient.Get(endpoint, &res); err != nil { | ||
return diag.FromErr(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 | ||
} |
87 changes: 87 additions & 0 deletions
87
ovh/data_cloud_project_database_kafka_schemaregistryacls_test.go
This file contains hidden or 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 testAccCloudProjectDatabaseKafkaSchemaregistryaclsDatasourceConfig_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_schemaregistryacl" "schemaRegistryAcl" { | ||
service_name = ovh_cloud_project_database.db.service_name | ||
cluster_id = ovh_cloud_project_database.db.id | ||
permission = "%s" | ||
resource = "%s" | ||
username = "%s" | ||
} | ||
|
||
data "ovh_cloud_project_database_kafka_schemaregistryacls" "schemaRegistryAcls" { | ||
service_name = ovh_cloud_project_database_kafka_acl.acl.service_name | ||
cluster_id = ovh_cloud_project_database_kafka_acl.acl.cluster_id | ||
} | ||
` | ||
|
||
func TestAccCloudProjectDatabaseKafkaSchemaregistryaclsDataSource_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 := "schema_registry_read" | ||
aclResource := "Subject:myResource" | ||
username := "johnDoe" | ||
|
||
config := fmt.Sprintf( | ||
testAccCloudProjectDatabaseKafkaAclsDatasourceConfig_Basic, | ||
serviceName, | ||
description, | ||
version, | ||
region, | ||
region, | ||
region, | ||
flavor, | ||
permission, | ||
aclResource, | ||
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_schemaregistryacls.schemaRegistryAcls", | ||
"acl_ids.#", | ||
), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.