-
Notifications
You must be signed in to change notification settings - Fork 3
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
ENG-12435: Uptake of new Listener API with override repo tls flag and tls mode. #441
base: main
Are you sure you want to change the base?
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 | ||||
---|---|---|---|---|---|---|
|
@@ -14,25 +14,37 @@ import ( | |||||
// create a constant block for schema keys | ||||||
|
||||||
const ( | ||||||
RepoTypesKey = "repo_types" | ||||||
NetworkAddressKey = "network_address" | ||||||
MySQLSettingsKey = "mysql_settings" | ||||||
DbVersionKey = "db_version" | ||||||
CharacterSetKey = "character_set" | ||||||
S3SettingsKey = "s3_settings" | ||||||
ProxyModeKey = "proxy_mode" | ||||||
DynamoDbSettingsKey = "dynamodb_settings" | ||||||
RepoTypesKey = "repo_types" | ||||||
NetworkAddressKey = "network_address" | ||||||
MySQLSettingsKey = "mysql_settings" | ||||||
DbVersionKey = "db_version" | ||||||
CharacterSetKey = "character_set" | ||||||
S3SettingsKey = "s3_settings" | ||||||
ProxyModeKey = "proxy_mode" | ||||||
DynamoDbSettingsKey = "dynamodb_settings" | ||||||
OverrideRepoClientTlsSettingsKey = "override_repo_client_tls_settings" | ||||||
TlsModeKey = "tls_mode" | ||||||
) | ||||||
|
||||||
func tlsModes() []string { | ||||||
return []string{ | ||||||
"allow", // default, must be kept at position 0 | ||||||
"require", | ||||||
"disable", | ||||||
} | ||||||
} | ||||||
|
||||||
// SidecarListener struct for sidecar listener. | ||||||
type SidecarListener struct { | ||||||
SidecarId string `json:"-"` | ||||||
ListenerId string `json:"id"` | ||||||
RepoTypes []string `json:"repoTypes"` | ||||||
NetworkAddress *NetworkAddress `json:"address,omitempty"` | ||||||
MySQLSettings *MySQLSettings `json:"mysqlSettings,omitempty"` | ||||||
S3Settings *S3Settings `json:"s3Settings,omitempty"` | ||||||
DynamoDbSettings *DynamoDbSettings `json:"dynamoDbSettings,omitempty"` | ||||||
SidecarId string `json:"-"` | ||||||
ListenerId string `json:"id"` | ||||||
RepoTypes []string `json:"repoTypes"` | ||||||
NetworkAddress *NetworkAddress `json:"address,omitempty"` | ||||||
MySQLSettings *MySQLSettings `json:"mysqlSettings,omitempty"` | ||||||
S3Settings *S3Settings `json:"s3Settings,omitempty"` | ||||||
DynamoDbSettings *DynamoDbSettings `json:"dynamoDbSettings,omitempty"` | ||||||
OverrideRepoClientTlsSettings bool `json:"overrideRepoClientTlsSettings,omitempty"` | ||||||
TlsMode string `json:"tlsMode,omitempty"` | ||||||
} | ||||||
type NetworkAddress struct { | ||||||
Host string `json:"host,omitempty"` | ||||||
|
@@ -83,6 +95,8 @@ func (data ReadSidecarListenerAPIResponse) WriteToSchema(d *schema.ResourceData) | |||||
_ = d.Set(S3SettingsKey, data.ListenerConfig.S3SettingsAsInterface()) | ||||||
_ = d.Set(MySQLSettingsKey, data.ListenerConfig.MySQLSettingsAsInterface()) | ||||||
_ = d.Set(DynamoDbSettingsKey, data.ListenerConfig.DynamoDbSettingsAsInterface()) | ||||||
_ = d.Set(OverrideRepoClientTlsSettingsKey, data.ListenerConfig.OverrideRepoClientTlsSettings) | ||||||
_ = d.Set(TlsModeKey, data.ListenerConfig.TlsMode) | ||||||
} | ||||||
log.Printf("[DEBUG] End ReadSidecarListenerAPIResponse.WriteToSchema") | ||||||
return nil | ||||||
|
@@ -184,8 +198,10 @@ type SidecarListenerResource struct { | |||||
// ReadFromSchema populates the SidecarListenerResource from the schema | ||||||
func (s *SidecarListenerResource) ReadFromSchema(d *schema.ResourceData) error { | ||||||
s.ListenerConfig = SidecarListener{ | ||||||
SidecarId: d.Get(SidecarIDKey).(string), | ||||||
ListenerId: d.Get(ListenerIDKey).(string), | ||||||
SidecarId: d.Get(SidecarIDKey).(string), | ||||||
ListenerId: d.Get(ListenerIDKey).(string), | ||||||
OverrideRepoClientTlsSettings: d.Get(OverrideRepoClientTlsSettingsKey).(bool), | ||||||
TlsMode: d.Get(TlsModeKey).(string), | ||||||
} | ||||||
s.ListenerConfig.RepoTypesFromInterface(d.Get(RepoTypesKey).([]interface{})) | ||||||
s.ListenerConfig.NetworkAddressFromInterface(d.Get(NetworkAddressKey).(*schema.Set).List()) | ||||||
|
@@ -205,7 +221,7 @@ func resourceSidecarListener() *schema.Resource { | |||||
return &schema.Resource{ | ||||||
Description: "Manages [sidecar listeners](https://cyral.com/docs/sidecars/sidecar-listeners)." + | ||||||
"\n~> **Warning** Multiple listeners can be associated to a single sidecar as long as " + | ||||||
"`host` and `port` are unique. If `host` is ommitted, then `port` must be unique.", | ||||||
"`host` and `port` are unique. If `host` is omitted, then `port` must be unique.", | ||||||
CreateContext: CreateResource( | ||||||
ResourceOperationConfig{ | ||||||
Name: "SidecarListenersResourceCreate", | ||||||
|
@@ -402,5 +418,22 @@ func getSidecarListenerSchema() map[string]*schema.Schema { | |||||
}, | ||||||
}, | ||||||
}, | ||||||
OverrideRepoClientTlsSettingsKey: { | ||||||
Description: "Override TLS settings defined in the repo. " + | ||||||
"Default value generated by API if not provided. ", | ||||||
Type: schema.TypeBool, | ||||||
Optional: true, | ||||||
Computed: true, | ||||||
}, | ||||||
TlsModeKey: { | ||||||
Description: "TLS mode. " + | ||||||
"Default value generated by API if not provided. " + | ||||||
"Note! This field is in effect only if OverrideRepoClientTlsSettings is set to true or the listener " + | ||||||
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.
Suggested change
|
||||||
"is a SMART port (enabled in more than one binding). " + | ||||||
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. Suggestion: Is there a link in our public doc regarding smart ports? Might be interesting to add this link in this description as a reference for customers that want to understand how it works. I would also recommend adding a reference to the
Suggested change
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. Regarding the link to our public docs, please refer to the latest version instead of some specific release. |
||||||
"Allowed values: " + supportedTypesMarkdown(tlsModes()) + ".", | ||||||
Type: schema.TypeString, | ||||||
Optional: true, | ||||||
Computed: true, | ||||||
}, | ||||||
} | ||||||
} |
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.
@gengdahlCyral could you please also add validation for the possible values that are valid for this field? I understand that the API already does this validation and that it is easier to maintain if we don't duplicate the validation here in the terraform provider, but since the validation messages returned by the API are often not clear enough, adding a validation that is computed during the terraform plan instead of during the execution, and that also provides a proper message that explicitly mentions the error and which values are allowed for this field would improve the terraform provider UX overall, which is something we are aiming for in a recent conversation that I had with @wcmjunior. The validation could be something like: