Skip to content

Commit

Permalink
Replace the provider keyword with the extension keyword (#14379)
Browse files Browse the repository at this point in the history
As the first step of addressing
#14374, this PR replaces the
provider keyword with the extension keyword. Using the provider keyword
will now trigger a warning diagnostic with a code fix to assist users in
migrating to the new keyword.

To reduce the scope of this PR, the use of `provider` within the Bicep
CLI, Bicep configuration, and the codebase will be replaced separately
in subsequent PRs.

Closes #14378.
###### Microsoft Reviewers: [Open in
CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/14379)
  • Loading branch information
shenglol authored Jun 24, 2024
1 parent 0a695b5 commit 785c737
Show file tree
Hide file tree
Showing 24 changed files with 149 additions and 137 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
provider '../../temp/local-deploy/provider.tgz'
extension '../../temp/local-deploy/provider.tgz'

param payload string

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
provider '$TARGET_REFERENCE'
extension '$TARGET_REFERENCE'

resource dadJoke 'request@v1' = {
uri: 'https://icanhazdadjoke.com'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
provider '$TARGET_REFERENCE'
extension '$TARGET_REFERENCE'

resource dadJoke 'request@v1' = {
uri: 'https://icanhazdadjoke.com'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public async Task Publish_provider_should_succeed_to_filesystem()

var services = new ServiceBuilder().WithFileSystem(fs).WithFeatureOverrides(new(ExtensibilityEnabled: true, ProviderRegistry: true));
var compileResult = await CompilationHelper.RestoreAndCompile(services, """
provider '../../target/provider.tgz'
extension '../../target/provider.tgz'

resource fooRes 'fooType@v1' = {
identifier: 'foo'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CentralizedProviderVersionManagementTests : TestBase
public void ProvidersConfig_SupportForConfigManagedProviderDeclarationSyntax_When_ProviderIsBuiltIn(string providerIdentifier, bool shouldSucceed, (string code, DiagnosticLevel level, string message)[] expectedDiagnostics)
{
var result = CompilationHelper.Compile(Services, @$"
provider {providerIdentifier}
extension {providerIdentifier}
");

if (shouldSucceed)
Expand Down Expand Up @@ -55,7 +55,7 @@ public static IEnumerable<object[]> ProvidersConfig_SupportForConfigManagedProvi
"kubernetes",
false,
new (string, DiagnosticLevel, string)[] {
("BCP206", DiagnosticLevel.Error, "Provider namespace \"kubernetes\" requires configuration, but none was provided.") } };
("BCP206", DiagnosticLevel.Error, "Extension \"kubernetes\" requires configuration, but none was provided.") } };
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/Bicep.Core.IntegrationTests/DynamicAzTypesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task Az_namespace_can_be_used_without_configuration()
{
var services = await GetServices();
var result = await CompilationHelper.RestoreAndCompile(services, ("main.bicep", @$"
provider 'br/public:az:{BicepTestConstants.BuiltinAzProviderVersion}'
extension 'br/public:az:{BicepTestConstants.BuiltinAzProviderVersion}'
"));

result.Should().GenerateATemplate();
Expand All @@ -76,12 +76,12 @@ public async Task Az_namespace_errors_with_configuration()
{
var services = await GetServices();
var result = await CompilationHelper.RestoreAndCompile(services, @$"
provider 'br/public:az:{BicepTestConstants.BuiltinAzProviderVersion}' with {{}}
extension 'br/public:az:{BicepTestConstants.BuiltinAzProviderVersion}' with {{}}
");

result.Should().NotGenerateATemplate();
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[] {
("BCP205", DiagnosticLevel.Error, "Provider namespace \"az\" does not support configuration."),
("BCP205", DiagnosticLevel.Error, "Extension \"az\" does not support configuration."),
});
}

Expand All @@ -90,7 +90,7 @@ public async Task Az_namespace_can_be_used_with_alias()
{
var services = await GetServices();
var result = await CompilationHelper.RestoreAndCompile(services, @$"
provider 'br/public:az:{BicepTestConstants.BuiltinAzProviderVersion}' as testAlias
extension 'br/public:az:{BicepTestConstants.BuiltinAzProviderVersion}' as testAlias
");

result.Should().GenerateATemplate();
Expand All @@ -114,7 +114,7 @@ public async Task Az_namespace_can_be_used_with_bicepconfig_provider_alias()
"""));

var result = await CompilationHelper.RestoreAndCompile(services, @$"
provider 'br/customAlias:az:{BicepTestConstants.BuiltinAzProviderVersion}'
extension 'br/customAlias:az:{BicepTestConstants.BuiltinAzProviderVersion}'
");

result.Should().GenerateATemplate();
Expand All @@ -128,7 +128,7 @@ public async Task Inlined_Az_namespace_alias_is_not_specified_in_config_yields_d
.WithFeatureOverrides(new(ExtensibilityEnabled: true, DynamicTypeLoadingEnabled: true));

var result = await CompilationHelper.RestoreAndCompile(services, @"
provider 'br/notFound:az:0.2.661'
extension 'br/notFound:az:0.2.661'
");

result.Should().NotGenerateATemplate();
Expand Down Expand Up @@ -160,7 +160,7 @@ await RegistryHelper.PublishModuleToRegistryAsync(

// ACT
var result = await CompilationHelper.RestoreAndCompile(services, @$"
provider '{testArtifact.ToSpecificationString(':')}'
extension '{testArtifact.ToSpecificationString(':')}'
");

// ASSERT
Expand All @@ -184,7 +184,7 @@ public async Task Bicep_compiler_handles_corrupted_provider_package_gracefully(

// ACT
var result = await CompilationHelper.RestoreAndCompile(services, @$"
provider '{testArtifactAddress.ToSpecificationString(':')}'
extension '{testArtifactAddress.ToSpecificationString(':')}'
");

// ASSERT
Expand Down Expand Up @@ -226,7 +226,7 @@ public async Task Repository_not_found_in_registry(

// ACT
var result = await CompilationHelper.RestoreAndCompile(services, @$"
provider '{artifactRegistryAddress.ToSpecificationString(':')}'
extension '{artifactRegistryAddress.ToSpecificationString(':')}'
");

// ASSERT
Expand Down Expand Up @@ -315,7 +315,7 @@ public async Task External_Az_namespace_can_be_loaded_from_configuration()
}
"""));
var result = await CompilationHelper.RestoreAndCompile(services, ("main.bicep", @$"
provider az
extension az
"));

result.Should().GenerateATemplate();
Expand All @@ -333,7 +333,7 @@ public async Task BuiltIn_Az_namespace_can_be_loaded_from_configuration()
// "implicitProviders": ["az"]
// }
var result = await CompilationHelper.RestoreAndCompile(services, ("main.bicep", @$"
provider az
extension az
"));

result.Should().GenerateATemplate();
Expand All @@ -357,7 +357,7 @@ public async Task Az_namespace_can_be_loaded_dynamically_using_provider_configur
"""));
//ACT
var result = await CompilationHelper.RestoreAndCompile(services, ("main.bicep", @$"
provider az
extension az
"));
//ASSERT
result.Should().GenerateATemplate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task Radius_identifier_passing_works_as_defined()
var services = await GetServicesWithPrepublishedTypes();

var result = await CompilationHelper.RestoreAndCompile(services, """
provider 'br:example.azurecr.io/test/radius:1.0.0'
extension 'br:example.azurecr.io/test/radius:1.0.0'

@description('The base name of the test, used to qualify resources and namespaces')
param basename string
Expand Down Expand Up @@ -81,7 +81,7 @@ public async Task Radius_use_of_existing_works()
var services = await GetServicesWithPrepublishedTypes();

var result = await CompilationHelper.RestoreAndCompile(services, """
provider 'br:example.azurecr.io/test/radius:1.0.0'
extension 'br:example.azurecr.io/test/radius:1.0.0'

param bucketName string

Expand Down
46 changes: 23 additions & 23 deletions src/Bicep.Core.IntegrationTests/ExtensibilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ExtensibilityTests : TestBase
public void Bar_import_bad_config_is_blocked()
{
var result = CompilationHelper.Compile(Services, @"
provider bar with {
extension bar with {
madeUpProperty: 'asdf'
} as stg
");
Expand All @@ -48,11 +48,11 @@ provider bar with {
public void Bar_import_can_be_duplicated()
{
var result = CompilationHelper.Compile(Services, """
provider bar with {
extension bar with {
connectionString: 'connectionString1'
} as stg

provider bar with {
extension bar with {
connectionString: 'connectionString2'
} as stg2
""");
Expand All @@ -63,7 +63,7 @@ provider bar with {
public void Bar_import_basic_test()
{
var result = CompilationHelper.Compile(Services, """
provider bar with {
extension bar with {
connectionString: 'asdf'
} as stg

Expand All @@ -84,11 +84,11 @@ provider bar with {
public void Ambiguous_type_references_return_errors()
{
var result = CompilationHelper.Compile(Services, """
provider bar with {
extension bar with {
connectionString: 'asdf'
} as stg

provider bar with {
extension bar with {
connectionString: 'asdf'
} as stg2

Expand All @@ -101,11 +101,11 @@ provider bar with {
});

result = CompilationHelper.Compile(Services, """
provider bar with {
extension bar with {
connectionString: 'asdf'
} as stg

provider bar with {
extension bar with {
connectionString: 'asdf'
} as stg2

Expand All @@ -120,7 +120,7 @@ provider bar with {
public void Bar_import_basic_test_loops_and_referencing()
{
var result = CompilationHelper.Compile(Services, """
provider bar with {
extension bar with {
connectionString: 'asdf'
} as stg

Expand Down Expand Up @@ -160,7 +160,7 @@ provider bar with {
public void Foo_import_basic_test_loops_and_referencing()
{
var result = CompilationHelper.Compile(Services, """
provider foo as foo
extension foo as foo
param numApps int

resource myApp 'application' = {
Expand Down Expand Up @@ -190,7 +190,7 @@ public void Foo_import_existing_requires_uniqueName()
{
// we've accidentally used 'name' even though this resource type doesn't support it
var result = CompilationHelper.Compile(Services, """
provider foo
extension foo

resource myApp 'application' existing = {
name: 'foo'
Expand All @@ -206,7 +206,7 @@ provider foo

// oops! let's change it to 'uniqueName'
result = CompilationHelper.Compile(Services, """
provider foo as foo
extension foo as foo

resource myApp 'application' existing = {
uniqueName: 'foo'
Expand All @@ -223,7 +223,7 @@ provider foo as foo
public void Kubernetes_import_existing_warns_with_readonly_fields()
{
var result = CompilationHelper.Compile(Services, """
provider kubernetes with {
extension kubernetes with {
namespace: 'default'
kubeConfig: ''
}
Expand Down Expand Up @@ -253,12 +253,12 @@ provider kubernetes with {
public void Kubernetes_competing_imports_are_blocked()
{
var result = CompilationHelper.Compile(Services, @"
provider kubernetes with {
extension kubernetes with {
namespace: 'default'
kubeConfig: ''
}
provider kubernetes with {
extension kubernetes with {
namespace: 'default'
kubeConfig: ''
}
Expand All @@ -277,7 +277,7 @@ provider kubernetes with {
public void Kubernetes_import_existing_resources()
{
var result = CompilationHelper.Compile(Services, @"
provider kubernetes with {
extension kubernetes with {
namespace: 'default'
kubeConfig: ''
}
Expand Down Expand Up @@ -313,7 +313,7 @@ provider kubernetes with {
public void Kubernetes_import_existing_connectionstring_test()
{
var result = CompilationHelper.Compile(Services, @"
provider kubernetes with {
extension kubernetes with {
namespace: 'default'
kubeConfig: ''
}
Expand Down Expand Up @@ -351,7 +351,7 @@ provider kubernetes with {
public void Kubernetes_CustomResourceType_EmitWarning()
{
var result = CompilationHelper.Compile(Services, """
provider kubernetes with {
extension kubernetes with {
namespace: 'default'
kubeConfig: ''
}
Expand All @@ -372,7 +372,7 @@ provider kubernetes with {
public void Kubernetes_AmbiguousFallbackType_MustFullyQualify()
{
var result = CompilationHelper.Compile(Services, """
provider kubernetes with {
extension kubernetes with {
namespace: 'default'
kubeConfig: ''
}
Expand Down Expand Up @@ -406,7 +406,7 @@ provider kubernetes with {
public void Bar_import_basic_test_with_qualified_type()
{
var result = CompilationHelper.Compile(Services, """
provider bar with {
extension bar with {
connectionString: 'asdf'
} as stg

Expand All @@ -427,7 +427,7 @@ provider bar with {
public void Invalid_namespace_qualifier_returns_error()
{
var result = CompilationHelper.Compile(Services, """
provider bar with {
extension bar with {
connectionString: 'asdf'
} as stg

Expand All @@ -452,7 +452,7 @@ provider bar with {
public void Child_resource_with_parent_namespace_mismatch_returns_error()
{
var result = CompilationHelper.Compile(Services, @"
provider bar with {
extension bar with {
connectionString: 'asdf'
} as stg
Expand Down Expand Up @@ -500,7 +500,7 @@ param accountName string
@secure()
param connectionString string
provider bar with {
extension bar with {
connectionString: connectionString
} as stg
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Core.IntegrationTests/OutputsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void Output_cannot_use_extensibility_resource_type()
{
var result = CompilationHelper.Compile(ServicesWithExtensibility,
"""
provider bar with {
extension bar with {
connectionString: 'asdf'
} as stg

Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Core.IntegrationTests/ParametersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ param p resource 'Some.Fake/Type@2019-06-01'
public void Parameter_cannot_use_extensibility_resource_type()
{
var result = CompilationHelper.Compile(ServicesWithExtensibility, """
provider bar with {
extension bar with {
connectionString: 'asdf'
} as stg

Expand Down
Loading

0 comments on commit 785c737

Please sign in to comment.