-
Notifications
You must be signed in to change notification settings - Fork 277
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
Databases: Set Kafka Connection Attributes (port, uri, private_uri) #1131
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,10 @@ const ( | |
mongoDBEngineSlug = "mongodb" | ||
mysqlDBEngineSlug = "mysql" | ||
redisDBEngineSlug = "redis" | ||
kafkaDBEngineSlug = "kafka" | ||
|
||
kafkaPublicSSLPort = 25073 | ||
kafkaPrivateSSLPort = 25080 | ||
) | ||
|
||
func ResourceDigitalOceanDatabaseCluster() *schema.Resource { | ||
|
@@ -307,7 +311,7 @@ func resourceDigitalOceanDatabaseClusterCreate(ctx context.Context, d *schema.Re | |
|
||
// MongoDB clusters only return the password in response to the initial POST. | ||
// We need to set it here before any subsequent GETs. | ||
if database.EngineSlug == mongoDBEngineSlug { | ||
if database.EngineSlug == mongoDBEngineSlug || database.EngineSlug == kafkaDBEngineSlug { | ||
err = setDatabaseConnectionInfo(database, d) | ||
if err != nil { | ||
return diag.Errorf("Error setting connection info for database cluster: %s", err) | ||
|
@@ -609,8 +613,12 @@ func flattenMaintWindowOpts(opts godo.DatabaseMaintenanceWindow) []map[string]in | |
func setDatabaseConnectionInfo(database *godo.Database, d *schema.ResourceData) error { | ||
if database.Connection != nil { | ||
d.Set("host", database.Connection.Host) | ||
d.Set("port", database.Connection.Port) | ||
d.Set("uri", database.Connection.URI) | ||
if database.EngineSlug == kafkaDBEngineSlug { | ||
// default for kafka will be Public SASL port, consistent with UI | ||
d.Set("port", kafkaPublicSSLPort) | ||
} else { | ||
d.Set("port", database.Connection.Port) | ||
} | ||
d.Set("database", database.Connection.Database) | ||
d.Set("user", database.Connection.User) | ||
if database.EngineSlug == mongoDBEngineSlug { | ||
|
@@ -622,6 +630,9 @@ func setDatabaseConnectionInfo(database *godo.Database, d *schema.ResourceData) | |
return err | ||
} | ||
d.Set("uri", uri) | ||
} else if database.EngineSlug == kafkaDBEngineSlug { | ||
uri := buildKafkaConnectionURI(database.Connection, kafkaPublicSSLPort) | ||
d.Set("uri", uri) | ||
} else { | ||
d.Set("password", database.Connection.Password) | ||
d.Set("uri", database.Connection.URI) | ||
|
@@ -636,6 +647,9 @@ func setDatabaseConnectionInfo(database *godo.Database, d *schema.ResourceData) | |
return err | ||
} | ||
d.Set("private_uri", uri) | ||
} else if database.EngineSlug == kafkaDBEngineSlug { | ||
uri := buildKafkaConnectionURI(database.PrivateConnection, kafkaPrivateSSLPort) | ||
d.Set("private_uri", uri) | ||
} else { | ||
d.Set("private_uri", database.PrivateConnection.URI) | ||
} | ||
|
@@ -661,6 +675,16 @@ func buildMongoDBConnectionURI(conn *godo.DatabaseConnection, d *schema.Resource | |
return uri.String(), nil | ||
} | ||
|
||
// DO API returns null values for uri and private uri for Kafka clusters. | ||
// buildKafkaConnectionURI sets the uri and private uri using connection's host. | ||
func buildKafkaConnectionURI(conn *godo.DatabaseConnection, port int) string { | ||
host := conn.Host | ||
|
||
uri := fmt.Sprintf("%s:%d", host, port) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets make sure that this is consistent with what the DBaaS team will eventually return from the API. Should there be a scheme? The other engines all seem to use the format There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Converting this PR to a draft as dbaas said they might actually get to it this week or next! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good! |
||
|
||
return uri | ||
} | ||
|
||
func expandBackupRestore(config []interface{}) *godo.DatabaseBackupRestore { | ||
backupRestoreConfig := config[0].(map[string]interface{}) | ||
|
||
|
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.
Are the ports guaranteed to be stable? Maybe we should grab it from the response? Something like: