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

feature: optionally enhanced location validation #6927

Merged
merged 1 commit into from May 18, 2020

Conversation

tombuildsstuff
Copy link
Member

This commit introduces a new optional feature, for the enhanced validation of Locations.

The Azure MetaData Service - that is: /metadata/endpoints?api-version=2018-01-01 returns information about the locations which are suppported on the Azure Instance that we're connected to. As such, this commit optionally caches this information with the intent of providing more granular validation - to avoid cases where an unsupported location is specified.

This allows Terraform to catch this error during terraform plan - rather than failing during terraform apply - which is a better user experience.

This functionality is disabled by default at this time - but can conditionally be enabled via the Feature Flag using the Environment Variable ARM_PROVIDER_ENHANCED_VALIDATION to true.

Example before/with this feature disabled:

 $ ARM_PROVIDER_ENHANCED_VALIDATION=false tf plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # azurerm_resource_group.test will be created
  + resource "azurerm_resource_group" "test" {
      + id       = (known after apply)
      + location = "chinanorth"
      + name     = "tom-dev99"

      + timeouts {
          + create = "60m"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy

Example with this feature enabled:

$ ARM_PROVIDER_ENHANCED_VALIDATION=true tf plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

------------------------------------------------------------------------

Error: "chinanorth" was not found in the list of supported Azure Locations: "westus,westus2,eastus,centralus,centraluseuap,southcentralus,northcentralus,westcentralus,eastus2,eastus2euap,brazilsouth,brazilus,northeurope,westeurope,eastasia,southeastasia,japanwest,japaneast,koreacentral,koreasouth,indiasouth,indiawest,indiacentral,australiaeast,australiasoutheast,canadacentral,canadaeast,uknorth,uksouth2,uksouth,ukwest,francecentral,francesouth,australiacentral,australiacentral2,uaecentral,uaenorth,southafricanorth,southafricawest,switzerlandnorth,switzerlandwest,germanynorth,germanywestcentral,norwayeast,norwaywest"

  on main.tf line 5, in resource "azurerm_resource_group" "test":
   5: resource "azurerm_resource_group" "test" {

@ghost ghost added the size/XL label May 14, 2020
@tombuildsstuff tombuildsstuff requested a review from a team May 14, 2020 13:30
if err != nil {
return nil, err
}
resp, err := client.Do(req)
Copy link
Member Author

Choose a reason for hiding this comment

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

note: this intentionally doesn't use Azure/go-autorest since we don't need it here (it's an unauthorized endpoint, and logging this isn't super valuable)

This commit introduces a new optional feature, for the enhanced validation of Locations.

The Azure MetaData Service - that is: /metadata/endpoints?api-version=2018-01-01 returns
information about the locations which are suppported on the Azure Instance that we're
connected to. As such, this commit optionally caches this information with the intent of
providing more granular validation - to avoid cases where an unsupported location is specified.

This allows Terraform to catch this error during `terraform plan` - rather than failing during
`terraform apply` - which is a better user experience.

This functionality is disabled by default at this time - but can conditionally be enabled
via the Feature Flag using the Environment Variable `ARM_PROVIDER_ENHANCED_VALIDATION` to `true`.

Example before/with this feature disabled:

```
 $ ARM_PROVIDER_ENHANCED_VALIDATION=false tf plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # azurerm_resource_group.test will be created
  + resource "azurerm_resource_group" "test" {
      + id       = (known after apply)
      + location = "chinanorth"
      + name     = "tom-dev99"

      + timeouts {
          + create = "60m"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy
```

Example with this feature enabled:

```
$ ARM_PROVIDER_ENHANCED_VALIDATION=true tf plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

------------------------------------------------------------------------

Error: "chinanorth" was not found in the list of supported Azure Locations: "westus,westus2,eastus,centralus,centraluseuap,southcentralus,northcentralus,westcentralus,eastus2,eastus2euap,brazilsouth,brazilus,northeurope,westeurope,eastasia,southeastasia,japanwest,japaneast,koreacentral,koreasouth,indiasouth,indiawest,indiacentral,australiaeast,australiasoutheast,canadacentral,canadaeast,uknorth,uksouth2,uksouth,ukwest,francecentral,francesouth,australiacentral,australiacentral2,uaecentral,uaenorth,southafricanorth,southafricawest,switzerlandnorth,switzerlandwest,germanynorth,germanywestcentral,norwayeast,norwaywest"

  on main.tf line 5, in resource "azurerm_resource_group" "test":
   5: resource "azurerm_resource_group" "test" {
```
@tombuildsstuff tombuildsstuff force-pushed the f/enhanced-location-validation branch from eaa0556 to 4e8b906 Compare May 14, 2020 13:34
@tombuildsstuff tombuildsstuff added this to the v2.11.0 milestone May 14, 2020
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.

LGTM 👍

@katbyte
Copy link
Collaborator

katbyte commented May 14, 2020

THou i wonder if we should add this property to the docs?

@tombuildsstuff
Copy link
Member Author

THou i wonder if we should add this property to the docs?

I'll add a section to the changelog for now, if we turn this on by default then it's probably worth documenting more broadly

@tombuildsstuff tombuildsstuff merged commit 9404b60 into master May 18, 2020
@tombuildsstuff tombuildsstuff deleted the f/enhanced-location-validation branch May 18, 2020 11:35
tombuildsstuff added a commit that referenced this pull request May 18, 2020
@ghost
Copy link

ghost commented May 22, 2020

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

@ghost
Copy link

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

@hashicorp hashicorp locked and limited conversation to collaborators Jun 17, 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.

None yet

2 participants