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

Site recovery support #4003

Merged
merged 23 commits into from Aug 19, 2019
Merged

Site recovery support #4003

merged 23 commits into from Aug 19, 2019

Conversation

martenbohlin
Copy link
Contributor

This pull request adds 6 new resources needed to support site recovery (Azure to Azure).

This fixes issue #3480

Let me know if I can improve the code in any way.

@martenbohlin
Copy link
Contributor Author

force-pushed to fix the lint errors that I had missed.

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.

Hi @martenbohlin,

Thank you for all these new resources! I've given this a first pass and its off to a great start. In addition to the comments i've left inline could we get some docs added for all the resources? As well as most of the errors need a little more detail added so when they happen we know what is erroring where.

thanks!


d.Set("name", resp.Name)
d.Set("resource_group_name", resGroup)
d.Set("location", resp.Properties.FriendlyName) // Crazy? yes. But the location comes back in the friendly name
Copy link
Collaborator

Choose a reason for hiding this comment

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

wow lol

There wil need to be a nil check here:

Suggested change
d.Set("location", resp.Properties.FriendlyName) // Crazy? yes. But the location comes back in the friendly name
if props := resp.Properties; props != nil {
d.Set("location", props.FriendlyName) // Crazy? yes. But the location comes back in the friendly name
}

ForceNew: true,
ValidateFunc: validate.NoEmptyStrings,
},
"name": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we put this at the tope before any other properties for consistency with the rest of the provider?

return &schema.Resource{
Create: resourceArmRecoveryNetworkMappingCreate,
Read: resourceArmRecoveryNetworkMappingRead,
Update: nil,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can just be left blank

Suggested change
Update: nil,

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

ForceNew: true,
ValidateFunc: validate.NoEmptyStrings,
},
"name": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we put this property up top as the first?

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

existing, err := client.Get(ctx, name)
if err != nil {
if !utils.ResponseWasNotFound(existing.Response) {
return fmt.Errorf("Error checking for presence of existing recovery services fabric: %+v", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

For this (and all other error messages) could e be a little more clear about what is erroring:

Suggested change
return fmt.Errorf("Error checking for presence of existing recovery services fabric: %+v", err)
return fmt.Errorf("Error checking for presence of existing recovery services fabric %s (vault %s): %+v", name, vaultName, err)


future, err := client.Create(ctx, fabricName, name, parameters)
if err != nil {
return fmt.Errorf("Error creating recovery services protection container1: %+v", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

As with all errors could we add a bit more detail:

Suggested change
return fmt.Errorf("Error creating recovery services protection container1: %+v", err)
return fmt.Errorf("Error creating recovery services protection container %s (fabric %s): %+v", name, fabricName, err)

Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.NoEmptyStrings,
Copy link
Collaborator

Choose a reason for hiding this comment

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

COuld we validate this is an ID?

Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.NoEmptyStrings,
Copy link
Collaborator

Choose a reason for hiding this comment

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

COuld we validate this is an ID?

@martenbohlin
Copy link
Contributor Author

Thanks @katbyte for the quick feedback. I have fixed all your comments about the code, and I will start to look at the documentation now.

It would be great if you could double check commit 63dcc2e where I upgrade the azure-sdk-for-go dependency, I am not sure if I updated the files under vendor correctly.

@ghost ghost removed the waiting-response label Aug 4, 2019
@martenbohlin
Copy link
Contributor Author

All requested changes has now been made.

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 for the revisions @martenbohlin,

I've left a couple more comments inline. WRT the sdk upgrade, we do that as a separate PR, i can open and get that merged for you once 1.33 is out.

I am seeing a few test failures thou:


------- Stdout: -------
=== RUN   TestAccAzureRMRecoveryReplicationPolicy_basic
=== PAUSE TestAccAzureRMRecoveryReplicationPolicy_basic
=== CONT  TestAccAzureRMRecoveryReplicationPolicy_basic

------- Stderr: -------
panic: Invalid address to set: []string{"location"}

looks like you are setting location, despite it not being part of the schema.

d.Set("name", resp.Name)
d.Set("resource_group_name", resGroup)
if props := resp.Properties; props != nil {
d.Set("location", props.FriendlyName) // Crazy? yes. But the location comes back in the friendly name
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might make sense to open an azure sdk bug for this one? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found the correct way to get the location now that I have worked a bit more with the API.

Required: true,
ForceNew: true,
ValidateFunc: validate.NoEmptyStrings,
DiffSuppressFunc: suppress.CaseDifference,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that we are fixing this at the d.Set(id) level can we remove this?

Required: true,
ForceNew: true,
ValidateFunc: validate.NoEmptyStrings,
DiffSuppressFunc: suppress.CaseDifference,
Copy link
Collaborator

Choose a reason for hiding this comment

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

as above

azurerm/resource_arm_recovery_services_replicated_vm.go Outdated Show resolved Hide resolved
@@ -1,7 +1,7 @@
module github.com/terraform-providers/terraform-provider-azurerm

require (
github.com/Azure/azure-sdk-for-go v31.0.0+incompatible
github.com/Azure/azure-sdk-for-go v31.1.0+incompatible
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we need to update the SDK that should be done in a separate PR, i can open that and get it merged for you once 1.33 goes out 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, that sounds great!

@martenbohlin
Copy link
Contributor Author

About the test failures, I can not reproduce that. I ran make testacc TESTARGS='-run=TestAccAzureRMRecoveryReplicationPolicy' and get a success. And I have also tried to run the other tests that I have added.

@ghost ghost removed the waiting-response label Aug 14, 2019
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.

@martenbohlin,

The error is because you are setting a property that doesn't exist in schema. i've marked them with some comments. This behaviour is not yet enabled by default, but you can with the environment variable: TF_SCHEMA_PANIC_ON_ERROR=1

}

d.Set("name", resp.Name)
d.Set("location", resp.Location)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You are setting location here and it doesn't exist in the schema

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aha, now I get it. Fixed.

d.Set("name", resp.Name)
d.Set("resource_group_name", resGroup)
d.Set("recovery_vault_name", vaultName)
d.Set("location", resp.Location)
Copy link
Collaborator

Choose a reason for hiding this comment

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

And here

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 for the fix @martenbohlin! LGTM now 🚀

@katbyte katbyte modified the milestones: v1.34.0, v1.33.0 Aug 19, 2019
@katbyte katbyte merged commit 4b4cce5 into hashicorp:master Aug 19, 2019
katbyte added a commit that referenced this pull request Aug 19, 2019
@sean-nixon
Copy link
Contributor

Super appreciative of the work on this and excited to try this out. Sorry to chime in out of nowhere but are these typos intentional? targert_disk_type and targert_replica_disk_type. I noticed them in the documentation updates as well as in the source code from the replicated VM resource. Just wanted to call that out before this gets released

@ghost ghost removed the waiting-response label Aug 19, 2019
@martenbohlin
Copy link
Contributor Author

@sean-nixon thanks for pointing that out. I have created pull request #4123 to fix the spelling mistakes.
@katbyte Will you merge that as well?

@ghost
Copy link

ghost commented Aug 22, 2019

This has been released in version 1.33.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.33.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Sep 19, 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 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Sep 19, 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.

None yet

3 participants