Skip to content

Commit 306877b

Browse files
New Feature - preflight initial implementation and POC (#32260)
Co-authored-by: Catriona <catriona@hashicorp.com> Co-authored-by: Catriona <86247157+catriona-m@users.noreply.github.com>
1 parent fa8aed1 commit 306877b

43 files changed

Lines changed: 3465 additions & 420 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

internal/clients/client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"context"
88
"fmt"
99

10+
preflight "github.com/hashicorp/terraform-provider-azurerm/internal/preflight/client"
11+
1012
"github.com/Azure/go-autorest/autorest"
1113
"github.com/Azure/go-autorest/autorest/validation"
1214
aadb2c_v2021_04_01_preview "github.com/hashicorp/go-azure-sdk/resource-manager/aadb2c/2021-04-01-preview"
@@ -160,6 +162,8 @@ type Client struct {
160162
Account *ResourceManagerAccount
161163
Features features.UserFeatures
162164

165+
Preflight *preflight.Client
166+
163167
AadB2c *aadb2c_v2021_04_01_preview.Client
164168
Advisor *advisor.Client
165169
AnalysisServices *analysisservices_v2017_08_01.Client
@@ -304,6 +308,10 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
304308

305309
var err error
306310

311+
if client.Preflight, err = preflight.NewClient(o); err != nil {
312+
return fmt.Errorf("building client for preflight validator: %+v", err)
313+
}
314+
307315
if client.AadB2c, err = aadb2c.NewClient(o); err != nil {
308316
return fmt.Errorf("building clients for AadB2c: %+v", err)
309317
}

internal/features/defaults.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ func Default() UserFeatures {
1313
EnhancedValidation: EnhancedValidationFeatures{
1414
Locations: !FivePointOh(),
1515
ResourceProviders: !FivePointOh(),
16+
PreflightEnabled: false,
17+
LocationFallback: nil,
1618
},
1719
AppConfiguration: AppConfigurationFeatures{
1820
PurgeSoftDeleteOnDestroy: true,

internal/features/enhanced_validation.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,28 @@ func ValidateEnhancedValidationEnvVars() error {
106106

107107
return nil
108108
}
109+
110+
// EnhancedValidationPreflightEnabled returns whether Azure Preflight Validation is enabled.
111+
//
112+
// Preflight validation is always opt-in and defaults to false in all provider versions.
113+
// Set ARM_PROVIDER_ENHANCED_VALIDATION_PREFLIGHT_ENABLED=true to enable it without
114+
// requiring an explicit config block.
115+
func EnhancedValidationPreflightEnabled() bool {
116+
if !FivePointOh() {
117+
return false
118+
}
119+
120+
return strings.EqualFold(os.Getenv("ARM_PROVIDER_ENHANCED_VALIDATION_PREFLIGHT_ENABLED"), "true")
121+
}
122+
123+
// EnhancedValidationLocationFallback returns the location fallback string for Azure Preflight Validation.
124+
//
125+
// This checks the `ARM_PROVIDER_ENHANCED_VALIDATION_LOCATION_FALLBACK` environment variable,
126+
// which can be used to set a default location for resources that don't have a specific location.
127+
func EnhancedValidationLocationFallback() *string {
128+
value := os.Getenv("ARM_PROVIDER_ENHANCED_VALIDATION_LOCATION_FALLBACK")
129+
if value != "" {
130+
return &value
131+
}
132+
return nil
133+
}

internal/features/user_flags.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ type UserFeatures struct {
1111
AppConfiguration AppConfigurationFeatures
1212
ApplicationInsights ApplicationInsightFeatures
1313
CognitiveAccount CognitiveAccountFeatures
14+
DatabricksWorkspace DatabricksWorkspaceFeatures
1415
EnhancedValidation EnhancedValidationFeatures
15-
VirtualMachine VirtualMachineFeatures
16-
VirtualMachineScaleSet VirtualMachineScaleSetFeatures
1716
KeyVault KeyVaultFeatures
18-
TemplateDeployment TemplateDeploymentFeatures
1917
LogAnalyticsWorkspace LogAnalyticsWorkspaceFeatures
20-
ResourceGroup ResourceGroupFeatures
21-
RecoveryServicesVault RecoveryServicesVault
18+
MachineLearning MachineLearningFeatures
2219
ManagedDisk ManagedDiskFeatures
23-
Storage StorageFeatures
24-
Subscription SubscriptionFeatures
20+
NetApp NetAppFeatures
2521
PostgresqlFlexibleServer PostgresqlFlexibleServerFeatures
26-
MachineLearning MachineLearningFeatures
2722
RecoveryService RecoveryServiceFeatures
28-
NetApp NetAppFeatures
29-
DatabricksWorkspace DatabricksWorkspaceFeatures
23+
RecoveryServicesVault RecoveryServicesVault
24+
ResourceGroup ResourceGroupFeatures
25+
Storage StorageFeatures
26+
Subscription SubscriptionFeatures
27+
TemplateDeployment TemplateDeploymentFeatures
28+
VirtualMachine VirtualMachineFeatures
29+
VirtualMachineScaleSet VirtualMachineScaleSetFeatures
3030
}
3131

3232
type CognitiveAccountFeatures struct {
@@ -36,6 +36,8 @@ type CognitiveAccountFeatures struct {
3636
type EnhancedValidationFeatures struct {
3737
Locations bool
3838
ResourceProviders bool
39+
PreflightEnabled bool
40+
LocationFallback *string
3941
}
4042

4143
type VirtualMachineFeatures struct {

0 commit comments

Comments
 (0)