Skip to content

Commit

Permalink
azurerm_mongo_cluster - move the validation to create func for `sou…
Browse files Browse the repository at this point in the history
…rce_server_id` (hashicorp#28269)

* azurerm_mongo_cluster - move the validation to create func for source_server_id

* update tc
  • Loading branch information
neil-yechenwei authored Dec 16, 2024
1 parent ccd6377 commit 6eb4009
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions internal/services/mongocluster/mongo_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ func (r MongoClusterResource) Create() sdk.ResourceFunc {
}

if state.CreateMode == string(mongoclusters.CreateModeGeoReplica) {
if state.SourceServerId == "" {
return fmt.Errorf("`source_server_id` is required when `create_mode` is `GeoReplica`")
}

parameter.Properties.ReplicaParameters = &mongoclusters.MongoClusterReplicaParameters{
SourceLocation: state.SourceLocation,
SourceResourceId: state.SourceServerId,
Expand Down Expand Up @@ -508,9 +512,6 @@ func (r MongoClusterResource) CustomizeDiff() sdk.ResourceFunc {
return fmt.Errorf("`version` is required when `create_mode` is %s", string(mongoclusters.CreateModeDefault))
}
case string(mongoclusters.CreateModeGeoReplica):
if state.SourceServerId == "" {
return fmt.Errorf("`source_server_id` is required when `create_mode` is `GeoReplica`")
}
if state.SourceLocation == "" {
return fmt.Errorf("`source_location` is required when `create_mode` is `GeoReplica`")
}
Expand Down
15 changes: 15 additions & 0 deletions internal/services/mongocluster/mongo_cluster_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ func TestAccMongoCluster_previewFeature(t *testing.T) {
})
}

func TestAccMongoCluster_geoReplica(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_mongo_cluster", "test")
r := MongoClusterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.geoReplica(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_password", "create_mode", "source_location"),
})
}

func (r MongoClusterResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := mongoclusters.ParseMongoClusterID(state.ID)
if err != nil {
Expand Down

0 comments on commit 6eb4009

Please sign in to comment.