Skip to content

Commit

Permalink
add PR comments/suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
EspenAlbert committed May 24, 2024
1 parent 0bdf6d5 commit b4964e6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const OIDC = "OIDC"

func Resource() *schema.Resource {
return &schema.Resource{
CreateContext: noOpCreate,
CreateContext: resourceCreateNotAllowed,
ReadContext: resourceMongoDBAtlasFederatedSettingsIdentityProviderRead,
UpdateContext: resourceMongoDBAtlasFederatedSettingsIdentityProviderUpdate,
DeleteContext: resourceMongoDBAtlasFederatedSettingsIdentityProviderDelete,
Expand Down Expand Up @@ -112,7 +112,7 @@ func Resource() *schema.Resource {
}
}

func noOpCreate(_ context.Context, _ *schema.ResourceData, _ any) diag.Diagnostics {
func resourceCreateNotAllowed(_ context.Context, _ *schema.ResourceData, _ any) diag.Diagnostics {
return diag.FromErr(errors.New("this resource must be imported"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func Resource() *schema.Resource {
return &schema.Resource{
CreateContext: noOpCreate,
CreateContext: resourceCreateNotAllowed,
ReadContext: resourceMongoDBAtlasFederatedSettingsOrganizationConfigRead,
UpdateContext: resourceMongoDBAtlasFederatedSettingsOrganizationConfigUpdate,
DeleteContext: resourceMongoDBAtlasFederatedSettingsOrganizationConfigDelete,
Expand Down Expand Up @@ -58,7 +58,7 @@ func Resource() *schema.Resource {
}
}

func noOpCreate(_ context.Context, _ *schema.ResourceData, _ any) diag.Diagnostics {
func resourceCreateNotAllowed(_ context.Context, _ *schema.ResourceData, _ any) diag.Diagnostics {
return diag.FromErr(errors.New("this resource must be imported"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
)

func TestAccFederatedSettingsOrgCreate_createError(t *testing.T) {
func TestAccFederatedSettingsOrg_createError(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Steps: []resource.TestStep{
{
Config: configBasic("not-used", "not-used", "not-used"),
Config: configBasic("not-used", "not-used", "not-used", "not-used"),
ExpectError: regexp.MustCompile("this resource must be imported"),
},
},
Expand All @@ -38,22 +38,23 @@ func basicTestCase(tb testing.TB) *resource.TestCase {
federationSettingsID = os.Getenv("MONGODB_ATLAS_FEDERATION_SETTINGS_ID")
orgID = os.Getenv("MONGODB_ATLAS_FEDERATED_ORG_ID")
idpID = os.Getenv("MONGODB_ATLAS_FEDERATED_IDP_ID")
associatedDomain = os.Getenv("MONGODB_ATLAS_FEDERATED_SETTINGS_ASSOCIATED_DOMAIN")
)

return &resource.TestCase{
PreCheck: func() { acc.PreCheckFederatedSettings(tb) },
PreCheck: func() { acc.PreCheckFederatedSettingsIdentityProvider(tb) },
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Steps: []resource.TestStep{
{
Config: configBasic(federationSettingsID, orgID, idpID),
Config: configBasic(federationSettingsID, orgID, idpID, associatedDomain),
ResourceName: resourceName,
ImportStateIdFunc: importStateIDFunc(federationSettingsID, orgID),
ImportState: true,
ImportStateVerify: false,
ImportStatePersist: true, // ensure update will be tested in the next step
},
{
Config: configBasic(federationSettingsID, orgID, idpID),
Config: configBasic(federationSettingsID, orgID, idpID, associatedDomain),
Check: resource.ComposeTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "federation_settings_id", federationSettingsID),
Expand All @@ -63,7 +64,7 @@ func basicTestCase(tb testing.TB) *resource.TestCase {
),
},
{
Config: configBasic(federationSettingsID, orgID, idpID),
Config: configBasic(federationSettingsID, orgID, idpID, associatedDomain),
ResourceName: resourceName,
ImportStateIdFunc: importStateIDFunc(federationSettingsID, orgID),
ImportState: true,
Expand Down Expand Up @@ -104,13 +105,13 @@ func importStateIDFunc(federationSettingsID, orgID string) resource.ImportStateI
}
}

func configBasic(federationSettingsID, orgID, identityProviderID string) string {
func configBasic(federationSettingsID, orgID, identityProviderID, associatedDomain string) string {
return fmt.Sprintf(`
resource "mongodbatlas_federated_settings_org_config" "test" {
federation_settings_id = "%[1]s"
org_id = "%[2]s"
domain_restriction_enabled = false
domain_allow_list = ["reorganizeyourworld.com", "cfn-test-domain.com"]
domain_allow_list = [%[4]q]
identity_provider_id = "%[3]s"
}`, federationSettingsID, orgID, identityProviderID)
}`, federationSettingsID, orgID, identityProviderID, associatedDomain)
}

0 comments on commit b4964e6

Please sign in to comment.