Skip to content

Commit 3844f95

Browse files
committed
require an extra flag to set DNS for the common services
1 parent 03b2cb4 commit 3844f95

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

cmd/cli/multiregion/dns.go

+32-19
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ import (
1717
)
1818

1919
type DnsCommand struct {
20-
cfClient *cloudflare.API
21-
cfZone *cloudflare.ResourceContainer
22-
domainName string
23-
env string
24-
failback bool
25-
region string
26-
region2 string
27-
testMode bool
20+
cfClient *cloudflare.API
21+
cfZone *cloudflare.ResourceContainer
22+
domainName string
23+
env string
24+
failback bool
25+
includeCommon bool
26+
region string
27+
region2 string
28+
testMode bool
2829
}
2930

3031
type DnsValues struct {
@@ -36,36 +37,39 @@ type DnsValues struct {
3637
}
3738

3839
func InitDnsCmd(parentCmd *cobra.Command) {
39-
var failback bool
40+
var failback, includeCommon bool
4041

4142
cmd := &cobra.Command{
4243
Use: "dns",
4344
Short: "DNS Failover and Failback",
4445
Long: `Configure DNS CNAME values for primary or secondary region hostnames. Default is failover, use --failback to switch back to the primary region.`,
4546
Run: func(cmd *cobra.Command, args []string) {
46-
runDnsCommand(failback)
47+
runDnsCommand(failback, includeCommon)
4748
},
4849
}
4950
parentCmd.AddCommand(cmd)
5051

5152
cmd.PersistentFlags().BoolVar(&failback, "failback", false,
5253
`set DNS records to switch back to primary`,
5354
)
55+
cmd.PersistentFlags().BoolVar(&includeCommon, "include-common", false,
56+
`also set DNS records for services used by every IdP`,
57+
)
5458
}
5559

56-
func runDnsCommand(failback bool) {
60+
func runDnsCommand(failback, includeCommon bool) {
5761
pFlags := getPersistentFlags()
5862

5963
if pFlags.readOnlyMode {
6064
fmt.Println("-- Read-only mode enabled --")
6165
}
6266

63-
d := newDnsCommand(pFlags, failback)
67+
d := newDnsCommand(pFlags, failback, includeCommon)
6468

6569
d.setDnsRecordValues(pFlags.idp)
6670
}
6771

68-
func newDnsCommand(pFlags PersistentFlags, failback bool) *DnsCommand {
72+
func newDnsCommand(pFlags PersistentFlags, failback, includeCommon bool) *DnsCommand {
6973
d := DnsCommand{
7074
testMode: pFlags.readOnlyMode,
7175
domainName: viper.GetString(flags.DomainName),
@@ -98,6 +102,7 @@ func newDnsCommand(pFlags PersistentFlags, failback bool) *DnsCommand {
98102
d.region2 = pFlags.secondaryRegion
99103

100104
d.failback = failback
105+
d.includeCommon = includeCommon
101106

102107
return &d
103108
}
@@ -119,10 +124,19 @@ func (d *DnsCommand) setDnsRecordValues(idpKey string) {
119124
supportBotName = "watson"
120125
}
121126

122-
dnsRecords := []struct {
127+
type nameValuePair struct {
123128
name string
124129
value string
125-
}{
130+
}
131+
132+
dnsRecords := []nameValuePair{
133+
// ECS services
134+
{idpKey + "-pw-api", idpKey + "-pw-api-" + region},
135+
{idpKey, idpKey + "-" + region},
136+
{idpKey + "-sync", idpKey + "-sync-" + region},
137+
}
138+
139+
common := []nameValuePair{
126140
// "mfa-api" is the TOTP API, also known as serverless-mfa-api
127141
{"mfa-api", "mfa-api-" + region},
128142

@@ -131,11 +145,10 @@ func (d *DnsCommand) setDnsRecordValues(idpKey string) {
131145

132146
// this is the idp-support-bot API that is configured in the Slack API dashboard
133147
{supportBotName, supportBotName + "-" + region},
148+
}
134149

135-
// ECS services
136-
{idpKey + "-pw-api", idpKey + "-pw-api-" + region},
137-
{idpKey, idpKey + "-" + region},
138-
{idpKey + "-sync", idpKey + "-sync-" + region},
150+
if d.includeCommon {
151+
dnsRecords = append(dnsRecords, common...)
139152
}
140153

141154
for _, record := range dnsRecords {

cmd/cli/multiregion/setup.go

+6
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,13 @@ func setMultiregionVariables(pFlags PersistentFlags) {
236236
func deleteUnusedVariables(pFlags PersistentFlags) {
237237
fmt.Println("\nDeleting unused variables...")
238238

239+
deleteVariablesFromWorkspace(pFlags, clusterWorkspace(pFlags), []string{
240+
"aws_region",
241+
"app_name",
242+
})
239243
deleteVariablesFromWorkspace(pFlags, databaseSecondaryWorkspace(pFlags), []string{
244+
"aws_region",
245+
"app_name",
240246
"backup_retention_period",
241247
"multi_az",
242248
"skip_final_snapshot",

0 commit comments

Comments
 (0)