From e5dbea5cab2f19772d31cd83e29b0c0bf7560bd4 Mon Sep 17 00:00:00 2001 From: simisoft-exo Date: Wed, 20 Nov 2024 14:08:46 +0000 Subject: [PATCH 01/16] datasource username fix --- pkg/resources/database/datasource_uri.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/pkg/resources/database/datasource_uri.go b/pkg/resources/database/datasource_uri.go index c8edb4ae..61e0a838 100644 --- a/pkg/resources/database/datasource_uri.go +++ b/pkg/resources/database/datasource_uri.go @@ -253,8 +253,6 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re var uri string var params map[string]interface{} - const adminUsername = "avnadmin" - switch data.Type.ValueString() { case "kafka": res, err := client.GetDBAASServiceKafka(ctx, data.Name.ValueString()) @@ -283,9 +281,10 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re return } + params = res.URIParams data.Schema = types.StringValue("mysql") - creds, err := client.RevealDBAASMysqlUserPassword(ctx, data.Name.ValueString(), adminUsername) + creds, err := client.RevealDBAASMysqlUserPassword(ctx, data.Name.ValueString(), params["user"].(string)) if err != nil { resp.Diagnostics.AddError( "Client Error", @@ -302,7 +301,6 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re return } - params = res.URIParams params["password"] = creds.Password case "pg": res, err := waitForDBAASService( @@ -319,9 +317,10 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re return } + params = res.URIParams data.Schema = types.StringValue("postgres") - creds, err := client.RevealDBAASPostgresUserPassword(ctx, data.Name.ValueString(), adminUsername) + creds, err := client.RevealDBAASPostgresUserPassword(ctx, data.Name.ValueString(), params["user"].(string)) if err != nil { resp.Diagnostics.AddError( "Client Error", @@ -337,7 +336,6 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re ) return } - params = res.URIParams params["password"] = creds.Password case "redis": res, err := waitForDBAASService( @@ -354,10 +352,10 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re return } + params = res.URIParams data.Schema = types.StringValue("rediss") - const redisDefaultUsername = "default" - creds, err := client.RevealDBAASRedisUserPassword(ctx, data.Name.ValueString(), redisDefaultUsername) + creds, err := client.RevealDBAASRedisUserPassword(ctx, data.Name.ValueString(), params["user"].(string)) if err != nil { resp.Diagnostics.AddError( "Client Error", @@ -390,9 +388,10 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re return } + params = res.URIParams data.Schema = types.StringValue("https") - creds, err := client.RevealDBAASOpensearchUserPassword(ctx, data.Name.ValueString(), adminUsername) + creds, err := client.RevealDBAASOpensearchUserPassword(ctx, data.Name.ValueString(), params["user"].(string)) if err != nil { resp.Diagnostics.AddError( "Client Error", @@ -409,7 +408,6 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re return } - params = res.URIParams params["password"] = creds.Password case "grafana": res, err := waitForDBAASService( @@ -427,9 +425,10 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re } uri = res.URI + params = res.URIParams data.Schema = types.StringValue("https") - creds, err := client.RevealDBAASGrafanaUserPassword(ctx, data.Name.ValueString(), adminUsername) + creds, err := client.RevealDBAASGrafanaUserPassword(ctx, data.Name.ValueString(), params["user"].(string)) if err != nil { resp.Diagnostics.AddError( "Client Error", @@ -438,7 +437,6 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re return } - params = res.URIParams params["password"] = creds.Password } From 79d7e845ce8e90c27da980c0153d5482fa5c4dd1 Mon Sep 17 00:00:00 2001 From: simisoft-exo Date: Wed, 20 Nov 2024 14:16:20 +0000 Subject: [PATCH 02/16] datasource test with test username --- pkg/resources/database/datasource_uri_test.go | 1 + pkg/testutils/testutils.go | 1 + 2 files changed, 2 insertions(+) diff --git a/pkg/resources/database/datasource_uri_test.go b/pkg/resources/database/datasource_uri_test.go index 8eb528b6..6c229891 100644 --- a/pkg/resources/database/datasource_uri_test.go +++ b/pkg/resources/database/datasource_uri_test.go @@ -44,6 +44,7 @@ func testDataSourceURI(t *testing.T) { Plan: "hobbyist-2", Zone: testutils.TestZoneName, TerminationProtection: false, + AdminUsername: acctest.RandomWithPrefix(testutils.TestUsername), } buf := &bytes.Buffer{} err = tplResourcePg.Execute(buf, &resourcePg) diff --git a/pkg/testutils/testutils.go b/pkg/testutils/testutils.go index 745a2282..37a0ed68 100644 --- a/pkg/testutils/testutils.go +++ b/pkg/testutils/testutils.go @@ -23,6 +23,7 @@ import ( const ( Prefix = "test-terraform-exoscale" + TestUsername = "test-exo-username" TestDescription = "Created by the terraform-exoscale provider" TestZoneName = "bg-sof-1" TestInstanceTemplateName = "Linux Ubuntu 20.04 LTS 64-bit" From 8d9b9fbf1fc7c428fc5e6b4067b37629cb41f4bf Mon Sep 17 00:00:00 2001 From: simisoft-exo Date: Wed, 20 Nov 2024 14:53:12 +0000 Subject: [PATCH 03/16] whitespace --- pkg/resources/database/datasource_uri_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/resources/database/datasource_uri_test.go b/pkg/resources/database/datasource_uri_test.go index 6c229891..bdc02da8 100644 --- a/pkg/resources/database/datasource_uri_test.go +++ b/pkg/resources/database/datasource_uri_test.go @@ -44,7 +44,7 @@ func testDataSourceURI(t *testing.T) { Plan: "hobbyist-2", Zone: testutils.TestZoneName, TerminationProtection: false, - AdminUsername: acctest.RandomWithPrefix(testutils.TestUsername), + AdminUsername: acctest.RandomWithPrefix(testutils.TestUsername), } buf := &bytes.Buffer{} err = tplResourcePg.Execute(buf, &resourcePg) From d63529f1eb13915b39a3b7fe3afa2d00f74855a9 Mon Sep 17 00:00:00 2001 From: simisoft-exo Date: Wed, 20 Nov 2024 14:53:57 +0000 Subject: [PATCH 04/16] more whitespace --- pkg/testutils/testutils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/testutils/testutils.go b/pkg/testutils/testutils.go index 37a0ed68..ea9f7179 100644 --- a/pkg/testutils/testutils.go +++ b/pkg/testutils/testutils.go @@ -23,7 +23,7 @@ import ( const ( Prefix = "test-terraform-exoscale" - TestUsername = "test-exo-username" + TestUsername = "test-exo-username" TestDescription = "Created by the terraform-exoscale provider" TestZoneName = "bg-sof-1" TestInstanceTemplateName = "Linux Ubuntu 20.04 LTS 64-bit" From 55fe46eabea7f63f4b86baca49a528d6a23fe4ea Mon Sep 17 00:00:00 2001 From: simisoft-exo Date: Wed, 20 Nov 2024 15:28:22 +0000 Subject: [PATCH 05/16] username test fix --- pkg/resources/database/datasource_uri_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/resources/database/datasource_uri_test.go b/pkg/resources/database/datasource_uri_test.go index bdc02da8..6456a389 100644 --- a/pkg/resources/database/datasource_uri_test.go +++ b/pkg/resources/database/datasource_uri_test.go @@ -27,6 +27,7 @@ func testDataSourceURI(t *testing.T) { } fullResourceName := "data.exoscale_database_uri.test" + pgUsername := acctest.RandomWithPrefix(testutils.TestUsername) data := DataSourceURIModel{ ResourceName: "test", Name: "exoscale_database.test.name", @@ -44,7 +45,7 @@ func testDataSourceURI(t *testing.T) { Plan: "hobbyist-2", Zone: testutils.TestZoneName, TerminationProtection: false, - AdminUsername: acctest.RandomWithPrefix(testutils.TestUsername), + AdminUsername: pgUsername, } buf := &bytes.Buffer{} err = tplResourcePg.Execute(buf, &resourcePg) @@ -71,7 +72,7 @@ func testDataSourceURI(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet(fullResourceName, "uri"), resource.TestCheckResourceAttr(fullResourceName, "schema", "postgres"), - resource.TestCheckResourceAttr(fullResourceName, "username", "avnadmin"), + resource.TestCheckResourceAttr(fullResourceName, "username", pgUsername), resource.TestCheckResourceAttrSet(fullResourceName, "password"), resource.TestCheckResourceAttrSet(fullResourceName, "host"), resource.TestCheckResourceAttrSet(fullResourceName, "port"), From 58f4bac4594c1aced75a784ffd81d2584d8776dc Mon Sep 17 00:00:00 2001 From: simisoft-exo Date: Wed, 20 Nov 2024 16:03:48 +0000 Subject: [PATCH 06/16] changelog --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a93a77f5..b6d83764 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +BUG FIXES: + +- Fix for allowing admin_username for dbaas #396 + ## 0.61.1 BUG FIXES: @@ -10,7 +14,7 @@ BUG FIXES: IMPROVEMENTS: -- Fetching database credentials via dedicated API endpoints +- Fetching database credentials via dedicated API endpoints #395 ## 0.61.0 From e3c90d9108e3fe78075f15d0c5c305c6681e46e1 Mon Sep 17 00:00:00 2001 From: simisoft-exo Date: Thu, 21 Nov 2024 12:19:58 +0000 Subject: [PATCH 07/16] password for kafka and params guard --- pkg/resources/database/datasource_uri.go | 89 +++++++++++++++++++++--- 1 file changed, 81 insertions(+), 8 deletions(-) diff --git a/pkg/resources/database/datasource_uri.go b/pkg/resources/database/datasource_uri.go index 61e0a838..0e36f7b3 100644 --- a/pkg/resources/database/datasource_uri.go +++ b/pkg/resources/database/datasource_uri.go @@ -255,17 +255,39 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re switch data.Type.ValueString() { case "kafka": - res, err := client.GetDBAASServiceKafka(ctx, data.Name.ValueString()) + res, err := waitForDBAASService( + ctx, + client.GetDBAASServiceKafka, + data.Name.ValueString(), + func(s *exoscale.DBAASServiceKafka) string { return string(s.State) }, + ) if err != nil { resp.Diagnostics.AddError( "Client Error", - fmt.Sprintf("Unable to read Database Service kafka: %s", err), + fmt.Sprintf("Unable to read Database Service Kafka: %s", err), ) return } uri = res.URI - params = res.URIParams + params, err = paramsWithCheck(res.URIParams) + if err != nil { + resp.Diagnostics.AddError( + "Client Error", + fmt.Sprintf("Unable to check Database Service Kafka parameters: %s", err), + ) + return + } + + creds, err := client.RevealDBAASMysqlUserPassword(ctx, data.Name.ValueString(), params["user"].(string)) + if err != nil { + resp.Diagnostics.AddError( + "Client Error", + fmt.Sprintf("Unable to reveal Database Service MySQL secret: %s", err), + ) + return + } + params["password"] = creds.Password case "mysql": res, err := waitForDBAASService( ctx, @@ -281,7 +303,14 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re return } - params = res.URIParams + params, err = paramsWithCheck(res.URIParams) + if err != nil { + resp.Diagnostics.AddError( + "Client Error", + fmt.Sprintf("Unable to check Database Service MySQL parameters: %s", err), + ) + return + } data.Schema = types.StringValue("mysql") creds, err := client.RevealDBAASMysqlUserPassword(ctx, data.Name.ValueString(), params["user"].(string)) @@ -317,7 +346,14 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re return } - params = res.URIParams + params, err = paramsWithCheck(res.URIParams) + if err != nil { + resp.Diagnostics.AddError( + "Client Error", + fmt.Sprintf("Unable to check Database Service Postgres parameters: %s", err), + ) + return + } data.Schema = types.StringValue("postgres") creds, err := client.RevealDBAASPostgresUserPassword(ctx, data.Name.ValueString(), params["user"].(string)) @@ -352,7 +388,14 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re return } - params = res.URIParams + params, err = paramsWithCheck(res.URIParams) + if err != nil { + resp.Diagnostics.AddError( + "Client Error", + fmt.Sprintf("Unable to check Database Service Redis parameters: %s", err), + ) + return + } data.Schema = types.StringValue("rediss") creds, err := client.RevealDBAASRedisUserPassword(ctx, data.Name.ValueString(), params["user"].(string)) @@ -388,7 +431,14 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re return } - params = res.URIParams + params, err = paramsWithCheck(res.URIParams) + if err != nil { + resp.Diagnostics.AddError( + "Client Error", + fmt.Sprintf("Unable to check Database Service Opensearch parameters: %s", err), + ) + return + } data.Schema = types.StringValue("https") creds, err := client.RevealDBAASOpensearchUserPassword(ctx, data.Name.ValueString(), params["user"].(string)) @@ -425,7 +475,14 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re } uri = res.URI - params = res.URIParams + params, err = paramsWithCheck(res.URIParams) + if err != nil { + resp.Diagnostics.AddError( + "Client Error", + fmt.Sprintf("Unable to check Database Service Grafana parameters: %s", err), + ) + return + } data.Schema = types.StringValue("https") creds, err := client.RevealDBAASGrafanaUserPassword(ctx, data.Name.ValueString(), params["user"].(string)) @@ -472,3 +529,19 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } + +func paramsWithCheck(params map[string]interface{}) (map[string]interface{}, error) { + if _, ok := params["host"]; !ok { + return nil, fmt.Errorf("host parameter is missing") + } + if _, ok := params["port"]; !ok { + return nil, fmt.Errorf("port parameter is missing") + } + if _, ok := params["user"]; !ok { + return nil, fmt.Errorf("user parameter is missing") + } + if _, ok := params["dbname"]; !ok { + return nil, fmt.Errorf("dbname parameter is missing") + } + return params, nil +} From 59ec3852636c7e59f7ffd393fb7e8bee852f0e98 Mon Sep 17 00:00:00 2001 From: simisoft-exo Date: Thu, 21 Nov 2024 12:32:03 +0000 Subject: [PATCH 08/16] user in it's own var and check --- pkg/resources/database/datasource_uri.go | 86 ++++++++++++++---------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/pkg/resources/database/datasource_uri.go b/pkg/resources/database/datasource_uri.go index 0e36f7b3..afb79d27 100644 --- a/pkg/resources/database/datasource_uri.go +++ b/pkg/resources/database/datasource_uri.go @@ -252,6 +252,7 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re var uri string var params map[string]interface{} + var user string switch data.Type.ValueString() { case "kafka": @@ -270,16 +271,20 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re } uri = res.URI - params, err = paramsWithCheck(res.URIParams) - if err != nil { + params = res.URIParams + if i, ok := params["user"]; ok { + if s, ok := i.(string); ok { + user = s + } + } else { resp.Diagnostics.AddError( "Client Error", - fmt.Sprintf("Unable to check Database Service Kafka parameters: %s", err), + "Database Service Kafka parameter user is missing", ) return } - creds, err := client.RevealDBAASMysqlUserPassword(ctx, data.Name.ValueString(), params["user"].(string)) + creds, err := client.RevealDBAASMysqlUserPassword(ctx, data.Name.ValueString(), user) if err != nil { resp.Diagnostics.AddError( "Client Error", @@ -303,17 +308,21 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re return } - params, err = paramsWithCheck(res.URIParams) - if err != nil { + params = res.URIParams + if i, ok := params["user"]; ok { + if s, ok := i.(string); ok { + user = s + } + } else { resp.Diagnostics.AddError( "Client Error", - fmt.Sprintf("Unable to check Database Service MySQL parameters: %s", err), + "Database Service MySQL parameter user is missing", ) return } data.Schema = types.StringValue("mysql") - creds, err := client.RevealDBAASMysqlUserPassword(ctx, data.Name.ValueString(), params["user"].(string)) + creds, err := client.RevealDBAASMysqlUserPassword(ctx, data.Name.ValueString(), user) if err != nil { resp.Diagnostics.AddError( "Client Error", @@ -346,17 +355,21 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re return } - params, err = paramsWithCheck(res.URIParams) - if err != nil { + params = res.URIParams + if i, ok := params["user"]; ok { + if s, ok := i.(string); ok { + user = s + } + } else { resp.Diagnostics.AddError( "Client Error", - fmt.Sprintf("Unable to check Database Service Postgres parameters: %s", err), + "Database Service Postgres parameter user is missing", ) return } data.Schema = types.StringValue("postgres") - creds, err := client.RevealDBAASPostgresUserPassword(ctx, data.Name.ValueString(), params["user"].(string)) + creds, err := client.RevealDBAASPostgresUserPassword(ctx, data.Name.ValueString(), user) if err != nil { resp.Diagnostics.AddError( "Client Error", @@ -388,17 +401,21 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re return } - params, err = paramsWithCheck(res.URIParams) - if err != nil { + params = res.URIParams + if i, ok := params["user"]; ok { + if s, ok := i.(string); ok { + user = s + } + } else { resp.Diagnostics.AddError( "Client Error", - fmt.Sprintf("Unable to check Database Service Redis parameters: %s", err), + "Database Service Redis parameter user is missing", ) return } data.Schema = types.StringValue("rediss") - creds, err := client.RevealDBAASRedisUserPassword(ctx, data.Name.ValueString(), params["user"].(string)) + creds, err := client.RevealDBAASRedisUserPassword(ctx, data.Name.ValueString(), user) if err != nil { resp.Diagnostics.AddError( "Client Error", @@ -414,7 +431,6 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re ) return } - params = res.URIParams params["password"] = creds.Password case "opensearch": res, err := waitForDBAASService( @@ -431,17 +447,21 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re return } - params, err = paramsWithCheck(res.URIParams) - if err != nil { + params = res.URIParams + if i, ok := params["user"]; ok { + if s, ok := i.(string); ok { + user = s + } + } else { resp.Diagnostics.AddError( "Client Error", - fmt.Sprintf("Unable to check Database Service Opensearch parameters: %s", err), + "Database Service Opensearch parameter user is missing", ) return } data.Schema = types.StringValue("https") - creds, err := client.RevealDBAASOpensearchUserPassword(ctx, data.Name.ValueString(), params["user"].(string)) + creds, err := client.RevealDBAASOpensearchUserPassword(ctx, data.Name.ValueString(), user) if err != nil { resp.Diagnostics.AddError( "Client Error", @@ -475,17 +495,21 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re } uri = res.URI - params, err = paramsWithCheck(res.URIParams) - if err != nil { + params = res.URIParams + if i, ok := params["user"]; ok { + if s, ok := i.(string); ok { + user = s + } + } else { resp.Diagnostics.AddError( "Client Error", - fmt.Sprintf("Unable to check Database Service Grafana parameters: %s", err), + "Database Service Grafana parameter user is missing", ) return } data.Schema = types.StringValue("https") - creds, err := client.RevealDBAASGrafanaUserPassword(ctx, data.Name.ValueString(), params["user"].(string)) + creds, err := client.RevealDBAASGrafanaUserPassword(ctx, data.Name.ValueString(), user) if err != nil { resp.Diagnostics.AddError( "Client Error", @@ -531,17 +555,5 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re } func paramsWithCheck(params map[string]interface{}) (map[string]interface{}, error) { - if _, ok := params["host"]; !ok { - return nil, fmt.Errorf("host parameter is missing") - } - if _, ok := params["port"]; !ok { - return nil, fmt.Errorf("port parameter is missing") - } - if _, ok := params["user"]; !ok { - return nil, fmt.Errorf("user parameter is missing") - } - if _, ok := params["dbname"]; !ok { - return nil, fmt.Errorf("dbname parameter is missing") - } return params, nil } From 9e198b0cec195610bbd349a68756e8e3ce19c7d3 Mon Sep 17 00:00:00 2001 From: simisoft-exo Date: Thu, 21 Nov 2024 12:36:39 +0000 Subject: [PATCH 09/16] cleanup --- pkg/resources/database/datasource_uri.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/resources/database/datasource_uri.go b/pkg/resources/database/datasource_uri.go index afb79d27..ed08deaa 100644 --- a/pkg/resources/database/datasource_uri.go +++ b/pkg/resources/database/datasource_uri.go @@ -554,6 +554,3 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } -func paramsWithCheck(params map[string]interface{}) (map[string]interface{}, error) { - return params, nil -} From c8282004491325cd046ac0265d3534c4eec6273a Mon Sep 17 00:00:00 2001 From: simisoft-exo Date: Thu, 21 Nov 2024 13:30:47 +0000 Subject: [PATCH 10/16] whitespace --- pkg/resources/database/datasource_uri.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/resources/database/datasource_uri.go b/pkg/resources/database/datasource_uri.go index ed08deaa..8cceb1f4 100644 --- a/pkg/resources/database/datasource_uri.go +++ b/pkg/resources/database/datasource_uri.go @@ -553,4 +553,3 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } - From b63fc93999759e1d2d90721c6f1625b08b73af23 Mon Sep 17 00:00:00 2001 From: simisoft-exo Date: Thu, 21 Nov 2024 15:42:30 +0000 Subject: [PATCH 11/16] longer timeout for kafka --- pkg/resources/database/testdata/datasource.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/resources/database/testdata/datasource.tmpl b/pkg/resources/database/testdata/datasource.tmpl index 53951b42..86fc1d6c 100644 --- a/pkg/resources/database/testdata/datasource.tmpl +++ b/pkg/resources/database/testdata/datasource.tmpl @@ -3,6 +3,6 @@ data "exoscale_database_uri" "{{ .ResourceName }}" { type = "{{ .Type }}" zone = "{{ .Zone }}" timeouts { - read = "20m" + read = "30m" } } From c44e25419411ed8f2328d83517a65fea30c2c4a1 Mon Sep 17 00:00:00 2001 From: simisoft-exo Date: Thu, 21 Nov 2024 15:48:28 +0000 Subject: [PATCH 12/16] checking user is a string --- pkg/resources/database/datasource_uri.go | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/pkg/resources/database/datasource_uri.go b/pkg/resources/database/datasource_uri.go index 8cceb1f4..9509417f 100644 --- a/pkg/resources/database/datasource_uri.go +++ b/pkg/resources/database/datasource_uri.go @@ -283,6 +283,13 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re ) return } + if user == "" { + resp.Diagnostics.AddError( + "Client Error", + "Database Service Kafka user is empty", + ) + return + } creds, err := client.RevealDBAASMysqlUserPassword(ctx, data.Name.ValueString(), user) if err != nil { @@ -320,6 +327,13 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re ) return } + if user == "" { + resp.Diagnostics.AddError( + "Client Error", + "Database Service MySQL user is empty", + ) + return + } data.Schema = types.StringValue("mysql") creds, err := client.RevealDBAASMysqlUserPassword(ctx, data.Name.ValueString(), user) @@ -367,6 +381,13 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re ) return } + if user == "" { + resp.Diagnostics.AddError( + "Client Error", + "Database Service Postgres user is empty", + ) + return + } data.Schema = types.StringValue("postgres") creds, err := client.RevealDBAASPostgresUserPassword(ctx, data.Name.ValueString(), user) @@ -385,6 +406,7 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re ) return } + params["password"] = creds.Password case "redis": res, err := waitForDBAASService( @@ -413,6 +435,13 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re ) return } + if user == "" { + resp.Diagnostics.AddError( + "Client Error", + "Database Service Redis user is empty", + ) + return + } data.Schema = types.StringValue("rediss") creds, err := client.RevealDBAASRedisUserPassword(ctx, data.Name.ValueString(), user) @@ -459,6 +488,13 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re ) return } + if user == "" { + resp.Diagnostics.AddError( + "Client Error", + "Database Service Opensearch user is empty", + ) + return + } data.Schema = types.StringValue("https") creds, err := client.RevealDBAASOpensearchUserPassword(ctx, data.Name.ValueString(), user) @@ -507,6 +543,13 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re ) return } + if user == "" { + resp.Diagnostics.AddError( + "Client Error", + "Database Service Grafana user is empty", + ) + return + } data.Schema = types.StringValue("https") creds, err := client.RevealDBAASGrafanaUserPassword(ctx, data.Name.ValueString(), user) From e921e1e851cc10112d242f8804090e8e4c2cea1f Mon Sep 17 00:00:00 2001 From: simisoft-exo Date: Fri, 22 Nov 2024 00:18:11 +0000 Subject: [PATCH 13/16] even longer timeout for kafka --- pkg/resources/database/testdata/datasource.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/resources/database/testdata/datasource.tmpl b/pkg/resources/database/testdata/datasource.tmpl index 86fc1d6c..a3516859 100644 --- a/pkg/resources/database/testdata/datasource.tmpl +++ b/pkg/resources/database/testdata/datasource.tmpl @@ -3,6 +3,6 @@ data "exoscale_database_uri" "{{ .ResourceName }}" { type = "{{ .Type }}" zone = "{{ .Zone }}" timeouts { - read = "30m" + read = "60m" } } From bfb42b17defde0dd7e257b91fd224567159c103f Mon Sep 17 00:00:00 2001 From: simisoft-exo Date: Fri, 22 Nov 2024 11:06:03 +0000 Subject: [PATCH 14/16] not needed for kafka --- pkg/resources/database/datasource_uri.go | 28 ------------------- .../database/testdata/datasource.tmpl | 2 +- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/pkg/resources/database/datasource_uri.go b/pkg/resources/database/datasource_uri.go index 9509417f..fa8bbcd2 100644 --- a/pkg/resources/database/datasource_uri.go +++ b/pkg/resources/database/datasource_uri.go @@ -272,34 +272,6 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re uri = res.URI params = res.URIParams - if i, ok := params["user"]; ok { - if s, ok := i.(string); ok { - user = s - } - } else { - resp.Diagnostics.AddError( - "Client Error", - "Database Service Kafka parameter user is missing", - ) - return - } - if user == "" { - resp.Diagnostics.AddError( - "Client Error", - "Database Service Kafka user is empty", - ) - return - } - - creds, err := client.RevealDBAASMysqlUserPassword(ctx, data.Name.ValueString(), user) - if err != nil { - resp.Diagnostics.AddError( - "Client Error", - fmt.Sprintf("Unable to reveal Database Service MySQL secret: %s", err), - ) - return - } - params["password"] = creds.Password case "mysql": res, err := waitForDBAASService( ctx, diff --git a/pkg/resources/database/testdata/datasource.tmpl b/pkg/resources/database/testdata/datasource.tmpl index a3516859..53951b42 100644 --- a/pkg/resources/database/testdata/datasource.tmpl +++ b/pkg/resources/database/testdata/datasource.tmpl @@ -3,6 +3,6 @@ data "exoscale_database_uri" "{{ .ResourceName }}" { type = "{{ .Type }}" zone = "{{ .Zone }}" timeouts { - read = "60m" + read = "20m" } } From 64aabe3384610a214bda8ba2d853f6cbc6257fdf Mon Sep 17 00:00:00 2001 From: simisoft-exo Date: Fri, 22 Nov 2024 12:07:39 +0000 Subject: [PATCH 15/16] reverting all kafka --- pkg/resources/database/datasource_uri.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pkg/resources/database/datasource_uri.go b/pkg/resources/database/datasource_uri.go index fa8bbcd2..195c3f42 100644 --- a/pkg/resources/database/datasource_uri.go +++ b/pkg/resources/database/datasource_uri.go @@ -256,12 +256,7 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re switch data.Type.ValueString() { case "kafka": - res, err := waitForDBAASService( - ctx, - client.GetDBAASServiceKafka, - data.Name.ValueString(), - func(s *exoscale.DBAASServiceKafka) string { return string(s.State) }, - ) + res, err := client.GetDBAASServiceKafka(ctx, data.Name.ValueString()) if err != nil { resp.Diagnostics.AddError( "Client Error", From 4318f88259853b18f018616d6a9363a67c379c95 Mon Sep 17 00:00:00 2001 From: simisoft-exo Date: Fri, 22 Nov 2024 12:15:43 +0000 Subject: [PATCH 16/16] cleanup --- pkg/resources/database/datasource_uri.go | 30 ------------------------ 1 file changed, 30 deletions(-) diff --git a/pkg/resources/database/datasource_uri.go b/pkg/resources/database/datasource_uri.go index 195c3f42..68e6d6ac 100644 --- a/pkg/resources/database/datasource_uri.go +++ b/pkg/resources/database/datasource_uri.go @@ -287,12 +287,6 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re if s, ok := i.(string); ok { user = s } - } else { - resp.Diagnostics.AddError( - "Client Error", - "Database Service MySQL parameter user is missing", - ) - return } if user == "" { resp.Diagnostics.AddError( @@ -341,12 +335,6 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re if s, ok := i.(string); ok { user = s } - } else { - resp.Diagnostics.AddError( - "Client Error", - "Database Service Postgres parameter user is missing", - ) - return } if user == "" { resp.Diagnostics.AddError( @@ -395,12 +383,6 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re if s, ok := i.(string); ok { user = s } - } else { - resp.Diagnostics.AddError( - "Client Error", - "Database Service Redis parameter user is missing", - ) - return } if user == "" { resp.Diagnostics.AddError( @@ -448,12 +430,6 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re if s, ok := i.(string); ok { user = s } - } else { - resp.Diagnostics.AddError( - "Client Error", - "Database Service Opensearch parameter user is missing", - ) - return } if user == "" { resp.Diagnostics.AddError( @@ -503,12 +479,6 @@ func (d *DataSourceURI) Read(ctx context.Context, req datasource.ReadRequest, re if s, ok := i.(string); ok { user = s } - } else { - resp.Diagnostics.AddError( - "Client Error", - "Database Service Grafana parameter user is missing", - ) - return } if user == "" { resp.Diagnostics.AddError(