mongodb / terraform-provider-mongodbatlas

Terraform MongoDB Atlas Provider: Deploy, update, and manage MongoDB Atlas infrastructure as code through HashiCorp Terraform
https://registry.terraform.io/providers/mongodb/mongodbatlas
Mozilla Public License 2.0
230 stars 167 forks source link

chore: Uses noOpCreate to avoid inconsistent result error and fix/enable tests in Ci #2290

Closed EspenAlbert closed 1 month ago

EspenAlbert commented 1 month ago

Description

This resource is not meant to be imported see docs (will get changed when we implement OIDC fully)

Original error showing:

module.federated_vars[0].mongodbatlas_federated_settings_identity_provider.identity_provider: Creating...
╷
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to module.federated_vars[0].mongodbatlas_federated_settings_identity_provider.identity_provider, provider "provider[\"registry.terraform.io/mongodb/mongodbatlas\"]" produced an unexpected new value: Root object was present, but now absent.
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

After refactoring:

│ Error: This resource must be imported
│
│   with module.federated_vars[0].mongodbatlas_federated_settings_identity_provider.identity_provider,
│   on modules/federated_vars/federated_vars.tf line 26, in resource "mongodbatlas_federated_settings_identity_provider" "identity_provider":
│   26: resource "mongodbatlas_federated_settings_identity_provider" "identity_provider" {

Link to any related issue(s): CLOUDP-248069

Type of change:

Required Checklist:

Further comments

mongodbatlas_federated_settings_org_config test

go test -timeout 2400s -run ^TestAccFederatedSettingsOrg_basic$ github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federatedsettingsorgconfig -v

=== RUN   TestAccFederatedSettingsOrg_basic
=== PAUSE TestAccFederatedSettingsOrg_basic
=== CONT  TestAccFederatedSettingsOrg_basic
--- PASS: TestAccFederatedSettingsOrg_basic (11.90s)
PASS
ok      github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federatedsettingsorgconfig  13.028s
marcosuma commented 1 month ago

@EspenAlbert I am trying to understand if the two things are related with each other: noOp and setId. Are they? Do we have acceptance tests in CI that are testing this path?

EspenAlbert commented 1 month ago

@marcosuma we have acceptance test for: mongodbatlas_federated_settings_identity_provider

But no acceptance test running in CI for mongodbatlas_federated_settings_org_config

Not sure if that answers your question. WDYT? I can work on enabling the test in the CI or at least run in locally for mongodbatlas_federated_settings_org_config

marcosuma commented 1 month ago

@EspenAlbert it seems like those tests can't be enabled, because I see acc.SkipTestForCI(tb) // affects the org as a comment. We should check with @AgustinBettati and team to see if there is a chance we can figure a way to enable them.

For sure running those tests locally is a workaround for this PR, make sure that removing SetId("") does not change the behaviour or introduces a bug

EspenAlbert commented 1 month ago

@marcosuma I have been running the tests locally and found a few issues, I had a meeting with @AgustinBettati and we discussed how to test these.

I'm working on enabling some of these tests in the CI and having this PR ready for review. Later, I believe a follow-up PR with full CRUD functionality and testing can be added for federated_settings_identity_provider using OIDC

marcosuma commented 1 month ago

Great, let's try to improve testing around this area. Just to confirm (I am still a bit unsure I have fully understood):

EspenAlbert commented 1 month ago

Great, let's try to improve testing around this area. Just to confirm (I am still a bit unsure I have fully understood):

  • you are adding the NoOp because by simply removing the if Id() == "" then SetId("" wouldn't be enough. Can you confirm?

Confirmed. After removing this check, it would fail on the read since Id() would be empty, and the read call would fail.

  • you have still not manage to test this correctly, right? I guess in this scenarios TDD can be handy

I have tested successfully 😄 Run in CI for the mongodbatlas_federated_settings_identity_provider

Local run for the TestAccFederatedSettingsOrg_basic:

go test -timeout 2400s -run ^TestAccFederatedSettingsOrg_basic$ github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federatedsettingsorgconfig -v

=== RUN   TestAccFederatedSettingsOrg_basic
=== PAUSE TestAccFederatedSettingsOrg_basic
=== CONT  TestAccFederatedSettingsOrg_basic
--- PASS: TestAccFederatedSettingsOrg_basic (11.90s)
PASS
ok      github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federatedsettingsorgconfig  13.028s
marcosuma commented 1 month ago

LGTM! Left some minor comments