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

Update Azure.Provisioning to latest version #5592

Merged
merged 37 commits into from
Sep 18, 2024
Merged

Conversation

eerhardt
Copy link
Member

@eerhardt eerhardt commented Sep 9, 2024

Update to the new Azure.Provisioning libraries.

Fix #5583

cc @mitchdenny @davidfowl @tg-msft @JoshLove-msft

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?
Microsoft Reviewers: Open in CodeFlow

Fix dotnet#5583

WIP: This first stab converts KeyVault to the new Provisioning version.
@davidfowl davidfowl added area-integrations Issues pertaining to Aspire Integrations packages azure Issues associated specifically with scenarios tied to using Azure and removed area-components labels Sep 10, 2024
AssignRole(StorageBuiltInRole.StorageTableDataContributor);
AssignRole(StorageBuiltInRole.StorageQueueDataContributor);

construct.Add(new BicepOutput("blobEndpoint", typeof(string)) { Value = storageAccount.PrimaryEndpoints.Value!.BlobUri });
Copy link
Member

Choose a reason for hiding this comment

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

@tg-msft why is .Value nullable?

Copy link
Contributor

Choose a reason for hiding this comment

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

BicepValue<T> is either a T? Value or an Expression? Expression. We have plans to clean this up so folks won't be using .Value!s and .Expression!s anywhere.

Comment on lines +65 to +69
new MemberExpression(
new MemberExpression(
new IdentifierExpression(keyVault.ResourceName),
"properties"),
"vaultUri")
Copy link
Member

Choose a reason for hiding this comment

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

Why doesn't storage look like this?

Copy link
Member Author

Choose a reason for hiding this comment

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

My understanding of @tg-msft's explanation is because the VaultUri property isn't parented directly under the KeyVaultService, but instead under the .Properties property. And that causes issues with the expressions. He is aware and is fixing this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Known issue related to an open design question around BicepValue<T> vs "T with internal expression" for models. I think folks are leaning toward the latter. Eventually this will be able to replaced with keyVault.Properties.VaultUri. (This is the same reason we had the .Value! in one of the other comments.)

keyVault.Tags["aspire-resource-name"] = construct.Resource.Name;

var role = KeyVaultBuiltInRole.KeyVaultAdministrator;
var roleAssignment = new RoleAssignment($"{KeyVaultBuiltInRole.GetBuiltInRoleName(role)}_{keyVault.ResourceName}")
Copy link
Member

@davidfowl davidfowl Sep 11, 2024

Choose a reason for hiding this comment

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

Does GetBuiltInRole have an interface (static interface method). We should be able to make this AssignRole method generic.

Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to punt on this with the new generated AssignRole overloads.

Copy link
Member Author

Choose a reason for hiding this comment

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

You should be able to punt on this with the new generated AssignRole overloads.

Yep, for all except WebPubSub, which doesn't have a BuiltInRole.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I just need to add some metadata to the spec (i.e., like this example) but didn't see anything documented at https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles other than SignalR/Web PubSub Contributor. I was going to follow-up with Liangying, but David beat me to it here. 😆 Are https://github.com/microsoft/azure-roles/blob/main/azure_roles.json#L585-L586 sufficient to add?

Copy link
Contributor

Choose a reason for hiding this comment

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

How about Azure/azure-sdk-for-net#45977 ? For some reason that the team is now investigating, the builtin roles for Web PubSub are listed in Preview category somehow, so that they are not seen in the documentation.

@@ -17,6 +18,10 @@ namespace Aspire.Hosting;
/// </summary>
public static class AzurePostgresExtensions
{
private const string ServerResourceVersion = "2023-03-01-preview";
Copy link
Member Author

Choose a reason for hiding this comment

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

@davidfowl @mitchdenny @tg-msft - how should we think about resource versions? Should we always hard-code the version we expect, and then periodically update to new versions on some sort of cadence? Similar to our other dependency versions.

Copy link
Contributor

Choose a reason for hiding this comment

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

At the moment I have everything default to "latest stable" in Azure.Provisioning.* (though I'm pulling the info from ARM so it's not perfect yet). The long term plan is to have Azure.Provisioning.* automatically release whenever the management plane libraries are updated so the "latest stable" will change seemingly at random.

As a general rule, moving to newer service versions is goodness for customers but there are occasionally breaking changes. We could float on latest by default and allow conservative customers to pin, or we could pin and have to manually test/bump the world a couple times a year. We might want to talk offline with Jeff Richter and Mike Kistler from Azure's Breaking Change Review Board for their advice on how dangerous it would be for customers to float on latest.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've decided to define these for all resources and put them in a shared file. Some things, like KeyVault, need to be used across many libraries. Thoughts on this approach?

Note I still need to ensure all resources use this pattern. Right now EventHubs doesn't.

Copy link
Member

Choose a reason for hiding this comment

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

I prefer updating the library and letting that determine the version of the default azure resource. If we don't do that then this will be just like container image tags except it'll be managed in both the Azure.Provisioning libraries and in aspire.

Copy link
Member Author

Choose a reason for hiding this comment

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

I would prefer that too, but there are problems with that approach.

  1. Not all resources have a default version in the CDK right now. Especially "child" resources. For those we need to provide a version, or else we get errors that it is unset.
  2. The default version for some things don't actually work. For example, the CDK doesn't emit an empty "properties" objects, but the default version for ServiceBus topics (I think it was this one) says that you must have a properties object. I can look up the exact error, if someone cares.
  3. The concern that updating to a new version will break something. @tg-msft assures me that there are breaking changes that happen from time to time. So if we just take the version that the CDK uses, and someone updates their CDK to a new version, with new default resource versions, there is a potential for our bicep to be broken.

Copy link
Contributor

Choose a reason for hiding this comment

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

1 is a bug that will be fixed by either generating the same default as parent resources or using a resolver to copy those. There's still a bit to design around the versioning story. I'd like to to have one list of versions per library, but there are some challenges there with ARM.

Let's follow up on 2. I currently try to omit as many empty objects as possible (i.e., no reason to serialize the entire object graph with empty braces everywhere) but we can design a way to include specific empty objects where needed if using a new ObjectExpression() isn't already a sufficient workaround.

@eerhardt
Copy link
Member Author

Tests are broken becuase I need to update the test nuget.config file for the new feed.

@radical - is it possible to not have the duplicate test nuget.config?

@radical
Copy link
Member

radical commented Sep 16, 2024

Tests are broken becuase I need to update the test nuget.config file for the new feed.

@radical - is it possible to not have the duplicate test nuget.config?

Yes, I will fix that.

The ones that still need to be specified are:

Top-level
- RedisResource
- SignalRService
- WebPubSubService

Child resources
- CognitiveServicesAccountDeployment
- CosmosDBSqlDatabase
- PostgreSqlFlexibleServerFirewallRule
- PostgreSqlFlexibleServerDatabase
- SqlFirewallRule
- SqlDatabase
@eerhardt
Copy link
Member Author

OK, I think this PR is ready for final review and can be merged to unblock other work.

There are follow up issues on the CDK we can make later.

  1. Default ResourceVersions for all resources.
  2. TimeSpan formatting for ServiceBus
  3. WebPubSub roles
  4. .Value! fix ups and using Expressions as workarounds.


resource keyVault_IeF8jZvXV 'Microsoft.KeyVault/vaults@2022-07-01' existing = {
name: keyVaultName
resource keyVault 'Microsoft.KeyVault/vaults@2019-09-01' existing = {
Copy link
Member

Choose a reason for hiding this comment

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

Why the downgrade in API version (surprising) /cc @tg-msft

Copy link
Contributor

Choose a reason for hiding this comment

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

Let me look into it.

@mitchdenny
Copy link
Member

OK I've done a full pass over this now. Its looking really good. I've left a few comments but the themes are:

  1. Resource name consistency between Aspire 8.0 and Aspire 9.0 (really important unless we've got a good reason to break it.
  2. Resource API version regressions in some areas (just need to understand why, and whether its going to cause problems. Would probably pay to deploy playground/cdk sample using 8.0 and 9.0 to the same target resource group and make sure it deploys cleanly (if the resource names line up and the config settings that change are mutable it should work fine.

Not specifically called out in comments above, but some of this has got a lot more verbose. That isn't a problem provided we provide really good documentation.

@davidfowl
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@davidfowl davidfowl merged commit fd0e633 into dotnet:main Sep 18, 2024
11 checks passed
@eerhardt eerhardt deleted the UpdateCDK branch October 2, 2024 00:03
@github-actions github-actions bot locked and limited conversation to collaborators Nov 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-integrations Issues pertaining to Aspire Integrations packages azure Issues associated specifically with scenarios tied to using Azure
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate new version of Azure.Provisioning
6 participants