Skip to content
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

azurerm_data_protection_backup_policy_postgresql: support target_copy_setting property #24476

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

sinbai
Copy link
Contributor

@sinbai sinbai commented Jan 12, 2024

When supporting targetDataStoreCopySettings property, it was found that TF is currently hard-coded for default azure retention rule and source data store partial value for the lifecycles(Additionally, there is the fact that for the default Azure retention rules/Azure retention rule, the lifecycle may have multiple items instead of the current hard-coded single item). The service team has confirmed that these properties are not immutable. I assume that these properties should be specified by the user.

Therefore, while submitting this PR to support targetDataStoreCopySettings, the original implementation (dependency) was changed and some properties were opened to users.

Test results:
image

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

}
} else {
// Add `life_cycle` in tf 4.0 since `retention_rule.#.life_cycle.#.target_copy_setting` and `retention_rule.#.life_cycle.#.data_store_type` should be specified by user and are not fixed.
resource.Schema["retention_rule"].Elem.(*pluginsdk.Resource).Schema["life_cycle"] = &pluginsdk.Schema{
Copy link
Member

Choose a reason for hiding this comment

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

Can multiple life_cycle blocks be specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"copy_after": {
Copy link
Member

Choose a reason for hiding this comment

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

What does this property do exactly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Specify when the backups are tiered across two or more selected data stores.

Copy link
Collaborator

Choose a reason for hiding this comment

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

that means this is a duration? should be call it copy_after_duration

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@katbyte thanks for your suggestion. copy_after really does not make it clear what this feature means. I assume that copy_option might be more suitable as the meaning of this feature is when to back up across two of more selected data stores. For example: Setting Immediate Copy means having a backup copy in both the standard vault and the archive vault simultaneously. Setting Copy On Expiry means moving the backup to vault-archive upon its expiry in vault-standard. WDYT?

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

Thanks @sinbai - this looks like the new property won't take affect till 4.0?

is it possible to implement them now inline and support a graceful deprecation path for users instead of the hard breaking change in 4.0? as well allowing them to be used before?

@sinbai
Copy link
Contributor Author

sinbai commented Mar 4, 2024

Thanks @sinbai - this looks like the new property won't take affect till 4.0?

is it possible to implement them now inline and support a graceful deprecation path for users instead of the hard breaking change in 4.0? as well allowing them to be used before?

Hi @katbyte thanks for your feedback and sounds like good suggestion. However, the newly added properties default_retention_rule and retention_rule.#.life_cycle should be required properties. If the original required attributes default_retention_duration and retention_rule.#.duration and the new two required are supported at the same time in the 3.0, these two sets of mutually exclusive attributes need to be modified to be optional. Then when the deprecated properties are deleted in the 4.0 , the new properties need to be changed to required. I assume this will be a breaking change (the new properties are changed from optional to required), so I assume this not appropriate, what do you think?

@katbyte
Copy link
Collaborator

katbyte commented Mar 5, 2024

Changing something from optional -> required during a major version is just fine! so lets make it optional & enable people using these properties now with the 4.0 flag flipping it to how things should behave in 4.0

@sinbai sinbai force-pushed the dataprotection/support_new_properties branch from 8d946c6 to ed5ce33 Compare March 7, 2024 03:56
@sinbai
Copy link
Contributor Author

sinbai commented Mar 7, 2024

Changing something from optional -> required during a major version is just fine! so lets make it optional & enable people using these properties now with the 4.0 flag flipping it to how things should behave in 4.0

Hi @katbyte thanks for your time and feedback. I have updated the code. Could you please take another look? Test results are as follows:
image


---

A `target_copy_setting` block supports the following:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think setting is redundant?

Suggested change
A `target_copy_setting` block supports the following:
A `target_copy` block supports the following:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


A `target_copy_setting` block supports the following:

* `copy_option` - (Required) Specifies when the backups are tiered across two or more selected data stores as a json encoded string. Changing this forces a new Backup Policy PostgreSQL to be created.
Copy link
Collaborator

Choose a reason for hiding this comment

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

and this might be better as

Suggested change
* `copy_option` - (Required) Specifies when the backups are tiered across two or more selected data stores as a json encoded string. Changing this forces a new Backup Policy PostgreSQL to be created.
* `option_json` - (Required) Specifies when the backups are tiered across two or more selected data stores as a json encoded string. Changing this forces a new Backup Policy PostgreSQL to be created.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines 37 to 43
"default_retention_duration",
"default_retention_rule.#",
"default_retention_rule.0.%",
"default_retention_rule.0.life_cycle.#",
"default_retention_rule.0.life_cycle.0.%",
"default_retention_rule.0.life_cycle.0.data_store_type",
"default_retention_rule.0.life_cycle.0.duration",
Copy link
Collaborator

Choose a reason for hiding this comment

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

are these not returned from the API? how come we are ignoring them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The API returns their values. However, TF supports both default_retention_duration (deprecated in v4.0) and default_retention_rule, which are two mutually exclusive properties in v3.0. These two properties corresponding to the same property of the API. Therefore, when importing resource in v3.0, I assume that we have no way of knowing whether the default_retention_duration or default_retention_rule is specified in the config, so I ignore them. Please see the following code in resourceDataProtectionBackupPolicyPostgreSQLRead func for details. Other than that, could you please let me know if there is a better solution?
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

in the past when i have deprecated a property and replaced it with another property i've made them both computed and then just set them both in read so they have a valid property, and then only sent the value that exists/has been set in config off to the api in update/create.

is this possible with these fields to do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @katbyte thank you very much, I think this is a very good way. But there is a little problem. If the deprecated and replaced properties are set in read at the same time, then the following checks need to be deleted at the same time. Do you think it's okay to remove the check?
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @katbyte a kind reminder in case you miss the above message.

@sinbai
Copy link
Contributor Author

sinbai commented Mar 12, 2024

Hi @katbyte I have updated the code to fix the comments above. The test results are as follows, could you please take another look? Thanks for your time.
image

Copy link

This PR is being labeled as "stale" because it has not been updated for 30 or more days.

If this PR is still valid, please remove the "stale" label. If this PR is blocked, please add it to the "Blocked" milestone.

If you need some help completing this PR, please leave a comment letting us know. Thank you!

@github-actions github-actions bot added the stale label Apr 15, 2024
@github-actions github-actions bot removed the stale label May 6, 2024
Copy link

This PR is being labeled as "stale" because it has not been updated for 30 or more days.

If this PR is still valid, please remove the "stale" label. If this PR is blocked, please add it to the "Blocked" milestone.

If you need some help completing this PR, please leave a comment letting us know. Thank you!

@github-actions github-actions bot added the stale label Jun 10, 2024
@stephybun
Copy link
Member

@sinbai having taken another look, this will require some significant rework before this can go in.

Before we go down that path though I have a specific question which is:

Has the request to add support for target_copy come from the service team or is this our own initiative to improve coverage here?

I ask because when creating a Backup Policy for PostgreSQL in the Portal, the option target copy setting isn't exposed at all and there is no way to set that information in the policy currently.

See the JSON excerpt below of the Backup Policy created via the portal:

{
    "properties": {
        "policyRules": [
            {
                "lifecycles": [
                    {
                        "deleteAfter": {
                            "objectType": "AbsoluteDeleteOption",
                            "duration": "P6M"
                        },
                        "targetDataStoreCopySettings": [],
                        "sourceDataStore": {
                            "dataStoreType": "VaultStore",
                            "objectType": "DataStoreInfoBase"
                        }
                    }
                ],
                "isDefault": false,
                "name": "Monthly",
                "objectType": "AzureRetentionRule"

@github-actions github-actions bot removed the stale label Jul 31, 2024
@sinbai
Copy link
Contributor Author

sinbai commented Aug 6, 2024

@sinbai having taken another look, this will require some significant rework before this can go in.

Before we go down that path though I have a specific question which is:

Has the request to add support for target_copy come from the service team or is this our own initiative to improve coverage here?

I ask because when creating a Backup Policy for PostgreSQL in the Portal, the option target copy setting isn't exposed at all and there is no way to set that information in the policy currently.

See the JSON excerpt below of the Backup Policy created via the portal:

{
    "properties": {
        "policyRules": [
            {
                "lifecycles": [
                    {
                        "deleteAfter": {
                            "objectType": "AbsoluteDeleteOption",
                            "duration": "P6M"
                        },
                        "targetDataStoreCopySettings": [],
                        "sourceDataStore": {
                            "dataStoreType": "VaultStore",
                            "objectType": "DataStoreInfoBase"
                        }
                    }
                ],
                "isDefault": false,
                "name": "Monthly",
                "objectType": "AzureRetentionRule"

Hi @stephybun sorry for the late reply. Yes, support for target_copy is a request from the service team. Also, I confirmed with the service team the necessity of this feature support and just received a positive response from them. Regarding the issue of not being visible via Portal, in fact, the feature is visible to some users/ vaults, see the picture below, and they will internally check the reason behind this.
image

@sinbai sinbai force-pushed the dataprotection/support_new_properties branch from 44780ff to 29ddef5 Compare November 7, 2024 06:02
@sinbai
Copy link
Contributor Author

sinbai commented Nov 7, 2024

@sinbai as 4.0 has been released could we update the PR with 5.0 flags?

addtionally i think the schema can be simplified

Hi @katbyte I have fixed the PR with 5.0 flags. Could you please take another look?

@katbyte
Copy link
Collaborator

katbyte commented Nov 7, 2024

@sinbai as per discussed on tuesday here is the breaking change & deprecation guide that this PR should follow: https://github.com/hashicorp/terraform-provider-azurerm/commits/main/contributing/topics/guide-breaking-changes.md

@sinbai
Copy link
Contributor Author

sinbai commented Nov 8, 2024

@sinbai as per discussed on tuesday here is the breaking change & deprecation guide that this PR should follow: https://github.com/hashicorp/terraform-provider-azurerm/commits/main/contributing/topics/guide-breaking-changes.md

Hi @katbyte , thanks for your time. I'm assuming I've followed the breaking changes and deprecation guidelines for now, please let me know if I've missed/misunderstood something. Thank you!

Test results in TC:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment