https://pulumi.com logo
#azure
Title
# azure
r

rapid-engineer-94232

06/29/2023, 11:41 AM
Hello! I'm using azure-native in C# and am experiencing some weird behavior. Would appreciated it if anyone could take a look. I have a stack for a system set up in Azure. When I try to change the tags of my resources, Pulumi insist that most of the resources should be deleted. I am using blob storage as a backend and have looked at the
dev.json
file that holds my state without finding any clues. The URNs still look correct, and the IDs that refer to the resources ids in Azure also look correct. I have attached screenshots from when I try to deploy the stack using V3.73.0 of the CLI on Windows (I also tried WSL with the same results). First image shows CLI results without any changes in code, the second shows the result when I change the tags of my resources. Pulumi.dev.yaml:
Copy code
config:
  Project:tags:
    - tag:
        key: department
        value: IT
    - tag:
        key: environment
        value: sandbox
    - tag:
        key: team
        value: web
    - tag:
        key: system
        value: website
Snippets from Program.cs:
Copy code
var tags = new InputMap<string>();

config.RequireObject<JsonElement[]>("tags")
    .ToList()
    .ForEach(element =>
        tags.Add(
            element.GetProperty("tag").GetProperty("key").GetString() ?? "",
            element.GetProperty("tag").GetProperty("value").GetString() ?? ""));


return new WebApp("webapp", new WebAppArgs
{
    ServerFarmId = appServicePlan.Id,
    Location = rg.Location,
    Name = "webapp",
    Tags = tags,
    ResourceGroupName = rg.Name,
    VirtualNetworkSubnetId = webAppSubnet.Id,
    Kind = "app,linux",
    ClientCertEnabled = false,
    HttpsOnly = true,
    Reserved = true,
    Enabled = true,
    StorageAccountRequired = false,
    Identity = new AzureNative.Web.Inputs.ManagedServiceIdentityArgs()
    {
        Type = ManagedServiceIdentityType.UserAssigned,
        UserAssignedIdentities =
        {
            [tuple.Item1] = new Dictionary<object, object>()
        }
    },
    SiteConfig = new SiteConfigArgs
    {
        AlwaysOn = true,
        NumberOfWorkers = 1,
        MinTlsVersion = "1.2",
        LinuxFxVersion = "DOTNETCORE|6.0",

        AppSettings = new List<NameValuePairArgs>
        {
            new NameValuePairArgs
            {
                Name = "DATBASE_HOST",
                Value = localhost
            },
        }
    }
}
, new CustomResourceOptions
{
    DependsOn =
    {
        DbNetRule
    }
});
Added images again in a thread:
m

melodic-tomato-39005

06/29/2023, 12:32 PM
Hi Lars, that’s odd. Can you 1. check whether there’s been any drift via
pulumi refresh
, and 2. run
pulumi preview --diff
to show more data?
r

rapid-engineer-94232

06/29/2023, 12:48 PM
Refresh shows some timestamp changes and a subnet change someone just manually made, so doesn't look like a lot of drift
In the preview, some resources show normal behavior changing the tags like so:
Copy code
~ azure-native:resources:ResourceGroup: (update)
    [id=/subscriptions/id/resourceGroups/appname-dev]
    [urn=urn:pulumi:dev::project.Infrastructure::azure-native:resources:ResourceGroup::appname-dev]
    [provider=urn:pulumi:dev::project.Infrastructure::pulumi:providers:azure-native::default_1_103_0::c4ad7357-cf22-4fea-8f17-f154b4f104bb]
  ~ tags: {
      ~ environment: "sandbox" => "dev"
    }
But others, like the webapp, are marked for deletion:
Copy code
- azure-native:web:WebApp: (delete)
    [id=/subscriptions/id/resourceGroups/appname-dev/providers/Microsoft.Web/sites/appname-app-dev]
    [urn=urn:pulumi:dev::project.Infrastructure::azure-native:web:WebApp::webapp]
    [provider=urn:pulumi:dev::project.Infrastructure::pulumi:providers:azure-native::default_1_103_0::c4ad7357-cf22-4fea-8f17-f154b4f104bb]
    clientCertEnabled     : false
    enabled               : true
    httpsOnly             : true
    hyperV                : false
    identity              : {
        type                  : "UserAssigned"
        userAssignedIdentities: {
            /subscriptions/id/resourcegroups/appname-dev/providers/Microsoft.ManagedIdentity/userAssignedIdentities/identity-name: {}
        }
    }
    isXenon               : false
    kind                  : "app,linux"
    location              : "norwayeast"
    name                  : "appname-app-dev"
    reserved              : true
    resourceGroupName     : "appname-dev"
    scmSiteAlsoStopped    : false
    serverFarmId          : "/subscriptions/id/resourceGroups/app-name/providers/Microsoft.Web/serverfarms/service-plan-name"
    siteConfig            : {
        alwaysOn           : true
        appSettings        : [
            [0]: {
                name : "DATABASE_HOST"
                value: "localhost"
            }
        ]
        http20Enabled      : true
        linuxFxVersion     : "DOTNETCORE|6.0"
        localMySqlEnabled  : false
        minTlsVersion      : "1.2"
        netFrameworkVersion: "v4.6"
        numberOfWorkers    : 1
    }
    storageAccountRequired: false
    tags                  : {
        department : "IT"
        environment: "sandbox"
        system     : "website"
        team       : "web"
    }
    virtualNetworkSubnetId: "/subscriptions/id/resourceGroups/vnet-rg/providers/Microsoft.Network/virtualNetworks/vnet-name/subnets/subnet-name"
In total:
Copy code
Resources:
    ~ 6 to update
    - 8 to delete
    14 changes. 12 unchanged
I'm pretty sure this was a mistake on my end since I have not been able to reproduce it since I posted this. We have a multi subscription environment and I suspect that I may have selected the wrong one in the Azure CLI. In short I think that my Pulumi stack and Azure subscription were not aligned.