Skip to content

Commit 5d93252

Browse files
maasthaCopilot
andauthored
feat: Adds new IsMongoDBGovCloud flag to profile (#1614)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent fbca024 commit 5d93252

4 files changed

Lines changed: 108 additions & 11 deletions

File tree

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,26 @@ Incorrect usage:
9191
"Profile" : "cfn/atlas/profile/ProfileName"
9292
```
9393

94+
## MongoDB Atlas for Government
95+
96+
MongoDB Atlas CloudFormation resources support [MongoDB Atlas for Government](https://www.mongodb.com/products/platform/atlas-for-government). To use Atlas for Government (Cloud Gov), configure the `IsMongoDBGovCloud` flag in your profile secret and use government-specific regions.
97+
98+
### Configure your Profile for Cloud Gov
99+
100+
When creating the profile secret in AWS Secrets Manager, include the `IsMongoDBGovCloud` field set to `true`:
101+
102+
```
103+
SecretName: cfn/atlas/profile/{ProfileName}
104+
SecretValue: {"PublicKey": "YourPublicKey", "PrivateKey": "YourPrivateKey", "IsMongoDBGovCloud": true}
105+
```
106+
107+
### Prerequisites
108+
1. Review [Atlas for Government considerations](https://www.mongodb.com/docs/atlas/government/atlas-for-government/).
109+
2. An existing Atlas Organization with billing set up in your Cloud Gov environment.
110+
3. API keys with the Organization Owner or Organization Project Creator role.
111+
112+
**Note**: Set `RegionUsageRestrictions` to `GOV_REGIONS_ONLY` on your project and use government-specific region names (e.g., `US_GOV_WEST_1` for AWS).
113+
94114
## Logging
95115

96116
Logging for AWS CloudFormation Public extensions is currently disabled. AWS is evaluating if logging is useful for consumers of third party extensions, if this is something you need or would like to request please open a ticket directly with AWS Support.
@@ -215,7 +235,3 @@ Resources:
215235
RouteTableCIDRBlock: "10.0.0.0/16"
216236
VpcId: "YOUR-VPC-ID"
217237
```
218-
219-
220-
221-

cfn-resources/profile/profile.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ import (
2929
)
3030

3131
const (
32-
DefaultProfile = "default"
32+
DefaultProfile = "default"
33+
GovCloudBaseURL = "https://cloud.mongodbgov.com/"
3334
)
3435

3536
type Profile struct {
36-
DebugClient *bool `json:"DebugClient,omitempty"`
37-
PublicKey string `json:"PublicKey"`
38-
PrivateKey string `json:"PrivateKey"`
39-
BaseURL string `json:"BaseUrl,omitempty"`
37+
DebugClient *bool `json:"DebugClient,omitempty"`
38+
IsMongoDBGovCloud *bool `json:"IsMongoDBGovCloud,omitempty"`
39+
PublicKey string `json:"PublicKey"`
40+
PrivateKey string `json:"PrivateKey"`
41+
BaseURL string `json:"BaseUrl,omitempty"`
4042
}
4143

4244
func NewProfile(req *handler.Request, profileName *string, prefixRequired bool) (*Profile, error) {
@@ -74,7 +76,15 @@ func (p *Profile) NewBaseURL() string {
7476
return baseURL
7577
}
7678

77-
return p.BaseURL
79+
if p.BaseURL != "" {
80+
return p.BaseURL
81+
}
82+
83+
if p.IsMongoDBGovCloud != nil && *p.IsMongoDBGovCloud {
84+
return GovCloudBaseURL
85+
}
86+
87+
return ""
7888
}
7989

8090
func (p *Profile) NewPublicKey() string {

cfn-resources/profile/profile_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"testing"
1919

2020
"github.com/mongodb/mongodbatlas-cloudformation-resources/profile"
21+
"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
2122
"github.com/stretchr/testify/assert"
2223
)
2324

@@ -32,3 +33,73 @@ func Test_UseDebug(t *testing.T) {
3233
profileTrue := profile.Profile{DebugClient: &trueBool}
3334
assert.True(t, profileTrue.UseDebug())
3435
}
36+
37+
func Test_NewBaseURL(t *testing.T) {
38+
tests := []struct {
39+
name string
40+
profile profile.Profile
41+
envURL string
42+
expected string
43+
}{
44+
{
45+
name: "empty profile returns empty string",
46+
profile: profile.Profile{},
47+
expected: "",
48+
},
49+
{
50+
name: "explicit BaseURL is returned",
51+
profile: profile.Profile{BaseURL: "https://custom.example.com/"},
52+
expected: "https://custom.example.com/",
53+
},
54+
{
55+
name: "IsMongoDBGovCloud true returns gov URL",
56+
profile: profile.Profile{IsMongoDBGovCloud: util.Pointer(true)},
57+
expected: profile.GovCloudBaseURL,
58+
},
59+
{
60+
name: "IsMongoDBGovCloud false returns empty string",
61+
profile: profile.Profile{IsMongoDBGovCloud: util.Pointer(false)},
62+
expected: "",
63+
},
64+
{
65+
name: "BaseURL takes precedence over IsMongoDBGovCloud",
66+
profile: profile.Profile{BaseURL: "https://custom.example.com/", IsMongoDBGovCloud: util.Pointer(true)},
67+
expected: "https://custom.example.com/",
68+
},
69+
{
70+
name: "env var takes precedence over BaseURL",
71+
profile: profile.Profile{BaseURL: "https://custom.example.com/"},
72+
envURL: "https://env.example.com/",
73+
expected: "https://env.example.com/",
74+
},
75+
{
76+
name: "env var takes precedence over IsMongoDBGovCloud",
77+
profile: profile.Profile{IsMongoDBGovCloud: util.Pointer(true)},
78+
envURL: "https://env.example.com/",
79+
expected: "https://env.example.com/",
80+
},
81+
{
82+
name: "env var takes precedence over both BaseURL and IsMongoDBGovCloud",
83+
profile: profile.Profile{BaseURL: "https://custom.example.com/", IsMongoDBGovCloud: util.Pointer(true)},
84+
envURL: "https://env.example.com/",
85+
expected: "https://env.example.com/",
86+
},
87+
{
88+
name: "IsMongoDBGovCloud nil returns empty string",
89+
profile: profile.Profile{IsMongoDBGovCloud: nil},
90+
expected: "",
91+
},
92+
}
93+
94+
for _, tc := range tests {
95+
t.Run(tc.name, func(t *testing.T) {
96+
if tc.envURL != "" {
97+
t.Setenv("MONGODB_ATLAS_BASE_URL", tc.envURL)
98+
} else {
99+
t.Setenv("MONGODB_ATLAS_BASE_URL", "")
100+
}
101+
result := tc.profile.NewBaseURL()
102+
assert.Equal(t, tc.expected, result)
103+
})
104+
}
105+
}

cfn-resources/util/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func newAtlasV2Client(req *handler.Request, profileName *string, profileNamePref
153153
HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}
154154
}
155155

156-
c := Config{BaseURL: prof.BaseURL, DebugClient: prof.UseDebug()}
156+
c := Config{BaseURL: prof.NewBaseURL(), DebugClient: prof.UseDebug()}
157157

158158
// new V2 version 20231115002 instance
159159
sdk20231115002Client, err := c.NewSDKv20231115002Client(client)

0 commit comments

Comments
 (0)