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

App Service: Add schedule backup functionality #3330

Closed
wants to merge 20 commits into from
Closed

App Service: Add schedule backup functionality #3330

wants to merge 20 commits into from

Conversation

namku
Copy link
Contributor

@namku namku commented Apr 29, 2019

Add schedule backup funcionality and documentation.

Copy link
Member

@mbfrahry mbfrahry left a 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,
Copy link
Member

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,
Copy link
Member

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 Show resolved Hide resolved
azurerm/resource_arm_app_service.go Outdated Show resolved Hide resolved
@@ -269,6 +285,22 @@ func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error
return err
}

backupSchedule := azure.ExpandAppServiceScheduleBackup(d.Get("backup_schedule"))
Copy link
Member

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") {
Copy link
Member

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

Copy link
Contributor

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?

@ghost ghost added size/XL and removed size/L labels May 25, 2019
@ghost ghost removed the size/XL label May 25, 2019
@ghost ghost added the size/L label May 25, 2019
@tombuildsstuff tombuildsstuff self-assigned this Jul 7, 2019
@tombuildsstuff tombuildsstuff added this to the v1.32.0 milestone Jul 7, 2019
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a 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,
},
Copy link
Contributor

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") {
Copy link
Contributor

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
}
Copy link
Contributor

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?

}
}
}

Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

could we make this:

Suggested change
# 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

could we make this:

Suggested change
This example provisions a schedule backup App Service.
This example provisions an App Service with a Backup configured.

tombuildsstuff added a commit that referenced this pull request Jul 7, 2019
```
$ 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
```
@tombuildsstuff
Copy link
Contributor

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!

tombuildsstuff added a commit that referenced this pull request Jul 17, 2019
```
$ 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
```
@ghost
Copy link

ghost commented Jul 30, 2019

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

@ghost ghost removed the waiting-response label Jul 30, 2019
@ghost
Copy link

ghost commented Aug 7, 2019

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!

@ghost ghost locked and limited conversation to collaborators Aug 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants