Skip to content

fix: Incompatible schema defined for mongodbatlas_backup_compliance_policy #1799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 3, 2024

Conversation

andreaangiolillo
Copy link
Collaborator

@andreaangiolillo andreaangiolillo commented Jan 2, 2024

Description

Ticket: https://jira.mongodb.org/browse/CLOUDP-220384

Bug:

Running tfplugindocs generate returns the following error:

Error executing command: unable to generate website: unable to render doc "mongodbatlas_backup_compliance_policy": unable to render template for "mongodbatlas_backup_compliance_policy": unable to render schema: unable to render schema: no match for "on_demand_policy_item", this can happen if you have incompatible schema defined, for example an optional block where all the child attributes are computed, in which case the block itself should also be marked computed 

Cause:

As the error message suggests this can happen if you have incompatible schema defined, for example an optional block where all the child attributes are computed, in which case the block itself should also be marked computed, the attribute on_demand_policy_item is marked as Optional while having all the child attributes as Computed

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contribution guidelines
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals, I defined an isolated PR with a relevant title as it will be used in the auto-generated changelog.

Further comments

@andreaangiolillo andreaangiolillo changed the title fix: incompatible schema defined for mongodbatlas_backup_compliance_policy fix: Incompatible schema defined for mongodbatlas_backup_compliance_policy Jan 2, 2024
@github-actions github-actions bot added the bug label Jan 2, 2024
@andreaangiolillo andreaangiolillo marked this pull request as ready for review January 2, 2024 14:04
@andreaangiolillo andreaangiolillo requested a review from a team as a code owner January 2, 2024 14:04
@@ -44,8 +44,7 @@ func DataSource() *schema.Resource {
},
"on_demand_policy_item": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Computed: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any potential breaking changes ? or plan change detections?
I am asking to make sure you've done some extra testing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while I do not see a risk in this change as project_id is documented as the only argument for the data source, we should consider also fixing inconsistencies present in policy_item_hourly, policy_item_daily, policy_item_weekly and policy_item_monthly which are not defined as computed. Error seems to only be raised in on_demand_policy_item because all nested attributes are computed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AgustinBettati All the policy_item_* fields have a few required parameters such as retention_unit and retention_value which is the reason why we are not getting the error for them.

Copy link
Collaborator Author

@andreaangiolillo andreaangiolillo Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcosuma I was able to test locally that this is not a breaking change.
Testing scenario:

  • Run the following configuration
resource "mongodbatlas_project" "atlas-project" {
  name   = "test-andrea"
  org_id = "XXXXXXXXXXXXXX"
}

resource "mongodbatlas_backup_compliance_policy" "backup_policy" {
  project_id                 = mongodbatlas_project.atlas-project.id
  authorized_email           = "[email protected]"
  authorized_user_first_name = "ssss"
  authorized_user_last_name  = "sss"
  copy_protection_enabled    = false
  pit_enabled                = false
  encryption_at_rest_enabled = false

  restore_window_days = 7

  on_demand_policy_item {
    frequency_interval = 1
    retention_unit     = "days"
    retention_value    = 3
  }

  policy_item_hourly {
    frequency_interval = 1
    retention_unit     = "days"
    retention_value    = 7
  }

  policy_item_daily {
    frequency_interval = 1
    retention_unit     = "days"
    retention_value    = 7
  }

  policy_item_weekly {
    frequency_interval = 1
    retention_unit     = "weeks"
    retention_value    = 4
  }

  policy_item_monthly {
    frequency_interval = 1
    retention_unit     = "months"
    retention_value    = 12
  }

}

data "mongodbatlas_backup_compliance_policy" "backup_policy" {
  project_id = mongodbatlas_backup_compliance_policy.backup_policy.project_id
}
  • Run TF apply with the latest provider
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
  • Updated the provider to use local version and run again terraform apply
No changes. Your infrastructure matches the configuration.

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure, is it possible that the relevant data source backup_compliance_policy was not tested in the above test configuration?

All the policy_item_* fields have a few required parameters such as retention_unit and retention_value which is the reason why we are not getting the error for them

Correct, I was bringing this up as I don't see why there should be optional or required attributes given that they should not be defined in the configuration of the data source. All of them should be computed except for project_id which is the only argument for using the data source.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure, is it possible that the relevant data source backup_compliance_policy was not tested in the above test configuration?

ops, I copied/pasted the wrong conf 🤦 I updated my message. Thanks!

Correct, I was bringing this up as I don't see why there should be optional or required attributes given that they should not be defined in the configuration of the data source. All of them should be computed except for project_id which is the only argument for using the data source.

Thanks for the clarification. I agree, I updated the schema to make them computed as well. I also retested the new changes with the TF conf and no changes where detected. Thanks!

Copy link
Member

@AgustinBettati AgustinBettati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the followup adjustments

@andreaangiolillo andreaangiolillo merged commit a5a2333 into master Jan 3, 2024
@andreaangiolillo andreaangiolillo deleted the CLOUDP-220384 branch January 3, 2024 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants