Skip to content

Commit

Permalink
Fix SQLServer discovery config generation (gravitational#20496)
Browse files Browse the repository at this point in the history
* Add tests for untested discovery flags (SQLServer, ElastiCache, MemoryDB)
  • Loading branch information
GavinFrazar authored Jan 25, 2023
1 parent 210e59c commit 08e3f75
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/config/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,9 @@ db_service:
"{{ $name }}": "{{ $value }}"
{{- end }}
{{- end }}
{{- if or .AzureMySQLDiscoveryRegions .AzurePostgresDiscoveryRegions .AzureRedisDiscoveryRegions}}
{{- if or .AzureMySQLDiscoveryRegions .AzurePostgresDiscoveryRegions .AzureRedisDiscoveryRegions .AzureSQLServerDiscoveryRegions }}
# Matchers for registering Azure-hosted databases.
azure:
{{- end }}
{{- if or .AzureMySQLDiscoveryRegions }}
# Azure MySQL databases auto-discovery.
# For more information about Azure MySQL auto-discovery: https://goteleport.com/docs/database-access/guides/azure-postgres-mysql/
Expand Down Expand Up @@ -258,6 +257,7 @@ db_service:
"{{ $name }}": "{{ $value }}"
{{- end }}
{{- end }}
{{- end }}
# Lists statically registered databases proxied by this agent.
{{- if .StaticDatabaseName }}
databases:
Expand Down
33 changes: 33 additions & 0 deletions lib/config/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,28 @@ func TestMakeDatabaseConfig(t *testing.T) {
require.ElementsMatch(t, flags.RedshiftDiscoveryRegions, databases.AWSMatchers[0].Regions)
})

t.Run("ElastiCacheAutoDiscovery", func(t *testing.T) {
flags := DatabaseSampleFlags{
ElastiCacheDiscoveryRegions: []string{"us-west-1", "us-west-2"},
}

databases := generateAndParseConfig(t, flags)
require.Len(t, databases.AWSMatchers, 1)
require.ElementsMatch(t, []string{"elasticache"}, databases.AWSMatchers[0].Types)
require.ElementsMatch(t, flags.ElastiCacheDiscoveryRegions, databases.AWSMatchers[0].Regions)
})

t.Run("MemoryDBAutoDiscovery", func(t *testing.T) {
flags := DatabaseSampleFlags{
MemoryDBDiscoveryRegions: []string{"us-west-1", "us-west-2"},
}

databases := generateAndParseConfig(t, flags)
require.Len(t, databases.AWSMatchers, 1)
require.ElementsMatch(t, []string{"memorydb"}, databases.AWSMatchers[0].Types)
require.ElementsMatch(t, flags.MemoryDBDiscoveryRegions, databases.AWSMatchers[0].Regions)
})

t.Run("AWS discovery tags", func(t *testing.T) {
flags := DatabaseSampleFlags{
RedshiftServerlessDiscoveryRegions: []string{"us-west-1", "us-west-2"},
Expand Down Expand Up @@ -118,6 +140,17 @@ func TestMakeDatabaseConfig(t *testing.T) {
require.ElementsMatch(t, flags.AzurePostgresDiscoveryRegions, databases.AzureMatchers[0].Regions)
})

t.Run("AzureSQLServerAutoDiscovery", func(t *testing.T) {
flags := DatabaseSampleFlags{
AzureSQLServerDiscoveryRegions: []string{"eastus", "eastus2"},
}

databases := generateAndParseConfig(t, flags)
require.Len(t, databases.AzureMatchers, 1)
require.ElementsMatch(t, []string{"sqlserver"}, databases.AzureMatchers[0].Types)
require.ElementsMatch(t, flags.AzureSQLServerDiscoveryRegions, databases.AzureMatchers[0].Regions)
})

t.Run("Azure discovery tags,subscriptions,resource_groups", func(t *testing.T) {
flags := DatabaseSampleFlags{
AzureRedisDiscoveryRegions: []string{"eastus", "eastus2"},
Expand Down

0 comments on commit 08e3f75

Please sign in to comment.