-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
App Service: Add schedule backup functionality #3330
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @namku, thanks for opening this PR. I can see you're on the right track but it needs a bit more work to get it merged - in particular:
- There are some unintended consequences with how Terraform will behave and the approach you're using and I've left some comments explaining that below. I'd suggest wrapping everything into a
backup
List and rewrite what you did to incorporate that. It not only fixes up some issues Terraform will see but neatly keeps track of all the attributes needed for a backup. - It looks like the backup isn't being read into the statefile, you'll want to add that to the read function.
- Once you get things rewritten, you'll need to add tests that create/update/delete a backup to make sure everything is hooked up and read into the statefile correctly.
Feel free to ask any questions if what I've said doesn't make sense.
Schema: map[string]*schema.Schema{ | ||
"frequency_interval": { | ||
Type: schema.TypeInt, | ||
Required: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any validation we can add here? Like greater than 0 and Less than some number?
"retention_period_in_days": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Default: 30, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts around validation here too?
azurerm/resource_arm_app_service.go
Outdated
@@ -269,6 +285,22 @@ func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error | |||
return err | |||
} | |||
|
|||
backupSchedule := azure.ExpandAppServiceScheduleBackup(d.Get("backup_schedule")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe we need this in the create method because this will be covered by the update that we go into immediately after creating.
@@ -338,6 +373,29 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error | |||
} | |||
} | |||
|
|||
if d.HasChange("backup_schedule") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're going to run into a perpetual Terraform state difference here if a user changes backup_name
or storage_account_url
without changing the backup_schedule
since those wouldn't get updated unless backup_schedule
has been changed. My above comment on wrapping everything into a backup
TypeList should fix this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to this - could we make this change?
Co-Authored-By: Matthew Frahry <[email protected]>
Co-Authored-By: Matthew Frahry <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @namku
Thanks for pushing those changes - I've taken a look through and left some comments inline but this is looking fairly good to me. So that we can get this merged, I hope you don't mind but I'm going to push some commits to resolve the pending comments.
Since this PR was opened from the master
branch of your fork, unfortunately that makes pushing a rebase complicated (since I can't push to that branch without breaking this PR). As such to do that I'm going to have to close this PR and open a new one, but this'll include the commits (and thus the credit) from this PR - I hope you don't mind; but this should allow us to ship this either way.
Thanks!
Type: schema.TypeString, | ||
Optional: true, | ||
ValidateFunc: validate.NoEmptyStrings, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we move all of these into a backup
block?
@@ -338,6 +373,29 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error | |||
} | |||
} | |||
|
|||
if d.HasChange("backup_schedule") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to this - could we make this change?
_, err = client.DeleteBackupConfiguration(ctx, resGroup, name) | ||
if err != nil { | ||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than calling this method - could we switch to calling these 4 lined directly above?
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we also read these values back into the State in the Read function (the Read function contains some examples of this)? this allows diff's to be detected
@@ -0,0 +1,3 @@ | |||
# Example: a Basic schedule backup App Service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we make this:
# Example: a Basic schedule backup App Service | |
# Example: an App Service with a Scheduled Backup |
@@ -0,0 +1,3 @@ | |||
# Example: a Basic schedule backup App Service | |||
|
|||
This example provisions a schedule backup App Service. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we make this:
This example provisions a schedule backup App Service. | |
This example provisions an App Service with a Backup configured. |
``` $ acctests azurerm TestAccAzureRMAppService_backup === RUN TestAccAzureRMAppService_backup === PAUSE TestAccAzureRMAppService_backup === CONT TestAccAzureRMAppService_backup --- PASS: TestAccAzureRMAppService_backup (660.26s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 660.313s ``` ``` $ acctests azurerm TestAccAzureRMAppService_basic === RUN TestAccAzureRMAppService_basic === PAUSE TestAccAzureRMAppService_basic === RUN TestAccAzureRMAppService_basicWindowsContainer === PAUSE TestAccAzureRMAppService_basicWindowsContainer === CONT TestAccAzureRMAppService_basic --- PASS: TestAccAzureRMAppService_basic (189.59s) === CONT TestAccAzureRMAppService_basicWindowsContainer --- PASS: TestAccAzureRMAppService_basicWindowsContainer (369.53s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 559.155s ```
hey @namku Apologies for the delayed re-review here! So that we can get this merged I've pulled these commits and the changes requested above into #3804 (since unfortunately it's not possible to rebase the master branch of a fork without breaking the PR, due to a bug with Github's Branch Protection) - which I'm going to close this in favour of #3804 (which includes your commits so you'll still be attributed for this contribution) - I hope you don't mind! Thanks! |
``` $ acctests azurerm TestAccAzureRMAppService_backup === RUN TestAccAzureRMAppService_backup === PAUSE TestAccAzureRMAppService_backup === CONT TestAccAzureRMAppService_backup --- PASS: TestAccAzureRMAppService_backup (660.26s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 660.313s ``` ``` $ acctests azurerm TestAccAzureRMAppService_basic === RUN TestAccAzureRMAppService_basic === PAUSE TestAccAzureRMAppService_basic === RUN TestAccAzureRMAppService_basicWindowsContainer === PAUSE TestAccAzureRMAppService_basicWindowsContainer === CONT TestAccAzureRMAppService_basic --- PASS: TestAccAzureRMAppService_basic (189.59s) === CONT TestAccAzureRMAppService_basicWindowsContainer --- PASS: TestAccAzureRMAppService_basicWindowsContainer (369.53s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 559.155s ```
This has been released in version 1.32.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example: provider "azurerm" {
version = "~> 1.32.0"
}
# ... other configuration ... |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
Add schedule backup funcionality and documentation.