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_cdn_endpoint - Standardize the resource ID to be case sensitive #8237

Merged

Conversation

magodo
Copy link
Collaborator

@magodo magodo commented Aug 25, 2020

This is a workaround for #Azure/azure-rest-api-specs#10576.

Fixes: #8191

Test Result

💢 make testacc TEST=./azurerm/internal/services/cdn/tests TESTARGS="-run='TestAccAzureRMCdnEndpoint_dnsAlias'"
==> Checking that code complies with gofmt requirements...
==> Checking that Custom Timeouts are used...                                                                          
==> Checking that acceptance test packages are used...
TF_ACC=1 go test ./azurerm/internal/services/cdn/tests -v -run='TestAccAzureRMCdnEndpoint_dnsAlias' -timeout 180m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccAzureRMCdnEndpoint_dnsAlias                                                                           
=== PAUSE TestAccAzureRMCdnEndpoint_dnsAlias            
=== CONT  TestAccAzureRMCdnEndpoint_dnsAlias               
--- PASS: TestAccAzureRMCdnEndpoint_dnsAlias (477.26s)
PASS                                                                                                                   
ok      github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cdn/tests   477.286s

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

Thanks for this PR - if we can add a couple of state migrations to patch the ID here then this otherwise LGTM 👍

Thanks!

@ghost ghost added size/XL and removed size/M labels Aug 25, 2020
@magodo
Copy link
Collaborator Author

magodo commented Aug 25, 2020

@tombuildsstuff I have added the migration logic, thank you for the example link!

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.

LGTM 👍

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.

Tests picked up a circular reference

@magodo
Copy link
Collaborator Author

magodo commented Aug 25, 2020

@tombuildsstuff I have resolved the CI errors, PTAL!

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.

Unfortunately due to the design of the new state migration functions we have to entirely duplicate the schema as a point-in-time copy - so we're unable to reuse this in the resource - incase this differs in the future

If we can duplicate that then this should otherwise be fine though 👍

return err
}),

Schema: tmpResource.Schema,
Copy link
Contributor

Choose a reason for hiding this comment

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

the schema needs to remain here - and be entirely duplicated for the migration; else if these differ in the future the original state migration schema is no longer valid - so unfortunately these cannot be reused and must be copy/pasted as a point-in-time reference to the current schema

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As this is a not a schema migration essentially, it is just the ID got migrated. I think it is fine to reuse the schema at this point.

If the schema got changed in the future, it should not impact the fact that the old ID format will be transitioned to the new one as long as the schema_version in state is 0. On the other hand, if the schema introduced a breaking change and we want to keep backward compatibility, then we can do a point-in-time copy at that time (like a copy-on-write style).

In this way, it is like that the version 0 schema keeps evolving until we decide to snapshot it in a fixed version at the time that we really want to do some schema level migration.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

The state migration system assumes there's a fixed point-in-time schema (e.g. only these fields exist, so unfortunately any additions would be a breaking change). Whilst we could technically reuse this at this point - the amount of change in this codebase makes it plausable we could unintentionally introduce a breaking change later - so it's better to follow the convention used by other state migrations and duplicate this.

Whilst it's unfortunate the state migration system is designed to require a schema (and we've raised this with the Plugin SDK Team, since this shouldn't be necessary, or should only require the specific attributes being modified for deserialization/serialization) - duplicating this removes the possibility of these unintentional bugs here, which are going to be incredibly hard to capture.

As such we're better to duplicate this schema in both instances.

return err
}),

Schema: tmpResource.Schema,
Copy link
Contributor

Choose a reason for hiding this comment

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

the schema needs to remain here - and be entirely duplicated for the migration; else if these differ in the future the original state migration schema is no longer valid - so unfortunately these cannot be reused and must be copy/pasted as a point-in-time reference to the current schema

@magodo
Copy link
Collaborator Author

magodo commented Aug 26, 2020

@tombuildsstuff I have added the dedicated PIT V0 schema as you suggested, please take another look! Thanks!

@tombuildsstuff tombuildsstuff changed the title azurerm_cnd_endpoint - Standardize the resource ID to be case sensitive azurerm_cdn_endpoint - Standardize the resource ID to be case sensitive Aug 27, 2020
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 @magodo

Thanks for pushing those changes - I've taken a look through and left some more comments inline but if we can duplicate the remaining schema here (and remove the validation funcs since these are unnecessary) then this should otherwise be good 👍🏻

Thanks!

azurerm/internal/services/cdn/migration/cdn_endpoint.go Outdated Show resolved Hide resolved
azurerm/internal/services/cdn/migration/cdn_endpoint.go Outdated Show resolved Hide resolved
azurerm/internal/services/cdn/migration/cdn_endpoint.go Outdated Show resolved Hide resolved
azurerm/internal/services/cdn/migration/cdn_endpoint.go Outdated Show resolved Hide resolved
azurerm/internal/services/cdn/migration/cdn_endpoint.go Outdated Show resolved Hide resolved
azurerm/internal/services/cdn/migration/cdn_endpoint.go Outdated Show resolved Hide resolved
azurerm/internal/services/cdn/migration/cdn_endpoint.go Outdated Show resolved Hide resolved
azurerm/internal/services/cdn/migration/cdn_endpoint.go Outdated Show resolved Hide resolved
azurerm/internal/services/cdn/migration/cdn_endpoint.go Outdated Show resolved Hide resolved
azurerm/internal/services/cdn/cdn_profile_resource.go Outdated Show resolved Hide resolved
@tombuildsstuff tombuildsstuff added this to the v2.26.0 milestone Aug 27, 2020
@ghost ghost removed the size/XL label Aug 27, 2020
@ghost ghost added the size/XXL label Aug 27, 2020
@magodo
Copy link
Collaborator Author

magodo commented Aug 27, 2020

@tombuildsstuff Done, I also expand the function invocation for fields like resource_group_name, location and tags.

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.

If we can make these consistent (these were missed in the last review cycle) then this otherwise LGTM 👍

azurerm/internal/services/cdn/parse/cdn_profile.go Outdated Show resolved Hide resolved
azurerm/internal/services/cdn/parse/cdn_endpoint.go Outdated Show resolved Hide resolved
@magodo
Copy link
Collaborator Author

magodo commented Aug 31, 2020

@tombuildsstuff I have renamed the parameters, please take another look!

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.

LGTM 👍

@tombuildsstuff
Copy link
Contributor

Tests pass:

Screenshot 2020-09-02 at 10 48 47

@tombuildsstuff tombuildsstuff merged commit 08539df into hashicorp:master Sep 2, 2020
tombuildsstuff added a commit that referenced this pull request Sep 2, 2020
@ghost
Copy link

ghost commented Sep 4, 2020

This has been released in version 2.26.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 = "~> 2.26.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Oct 2, 2020

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 as resolved and limited conversation to collaborators Oct 2, 2020
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.

azurerm_dns_a_record failing with weird "from no visitor picked" string in target_resource_id?
2 participants