Skip to content

fix: 'computed' and 'default' usage based on the documentation #1564

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 2 commits into from
Oct 26, 2023

Conversation

marcosuma
Copy link
Collaborator

@marcosuma marcosuma commented Oct 25, 2023

Description

Customer is complaining that using TF 1.0.8 certain fields are returning error because the provider (Atlas) is returning values but fields are not marked as "Computed". In other cases fields are marked as "Computed" but as per documentation these fields don't return values defined from the backend itself.

Documentation: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v1/#tag/Clusters/operation/updateClusterAdvancedConfiguration

Definition of "Computed": Computed indicates whether the provider may return its own value for this attribute or not. Computed cannot be used with Required. If Required and Optional are both false, the attribute will be considered "read only" for the practitioner, with only the provider able to set its value.

This needs to go after #1548

Link to any related issue(s): https://jira.mongodb.org/browse/HELP-51509

Customer cannot upgrade TF version

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 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

@marcosuma marcosuma added the bug label Oct 25, 2023
@marcosuma marcosuma changed the title fixes 'computed' and 'default' usage based on the documentation fix: 'computed' and 'default' usage based on the documentation Oct 25, 2023
@github-actions
Copy link
Contributor

Code Coverage

Package Line Rate Health
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas 2%
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/framework/validator 68%
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/util 12%
Summary 3% (271 / 10296)

@marcosuma marcosuma marked this pull request as ready for review October 25, 2023 15:17
@marcosuma marcosuma requested a review from a team as a code owner October 25, 2023 15:17
@@ -308,19 +308,16 @@ func resourceMongoDBAtlasCluster() *schema.Resource {
Type: schema.TypeSet,
Optional: true,
Set: HashFunctionForKeyValuePair,
Computed: true,
Copy link
Member

Choose a reason for hiding this comment

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

Is this a fix for the error "attribute representing nested block must not be unknown itself"? Or simply an improvement seeing Atlas API does not respond with labels.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's both basically - as per documentation nothing is returned and as you said it's deprecated.

I am really not sure why we used Computed here originally.

Copy link
Member

Choose a reason for hiding this comment

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

Yes agree that computed is not accurate in this case.
I am curious if the same scenario is happening with bi_connector_config and advanced_configuration which were bringing a similar issue, no need to adjust in this PR but more for my understanding in case you looked into it.

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 that's what I thought, but then something more complex happens there.
Why? What is the difference? The difference is that for labels we don't return anything, while for advanced_configuration the backend does return default value like:

  # advanced_configuration {
  #   # default_read_concern = ""
  #   # default_write_concern = ""
  #   fail_index_key_too_long = false
  #   javascript_enabled = true
  #   minimum_enabled_tls_protocol = "TLS1_2"
  #   no_table_scan = false
  #   oplog_min_retention_hours = 0
  #   # oplog_size_mb = 0
  #   sample_refresh_interval_bi_connector = 0
  #   sample_size_bi_connector = 0
  #   transaction_lifetime_limit_seconds = 0
  # }

hence when I do the terraform apply and it does a refresh and comparison it returns the error saying that it was expecting advanced_configuration count to be 0 but the read returned count 1 (which basically mean that when we read the backend we load that configuration because its values are default).

What I've just said should apply also for bi_connector_config but I haven't tested that.

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

@marcosuma marcosuma merged commit 93e2996 into master Oct 26, 2023
@marcosuma marcosuma deleted the HELP-51509-adjust-computed-accordingly branch October 26, 2023 09:19
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.

3 participants