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

adorable-scooter-32619

05/08/2023, 5:28 AM
Hi everyone, I am trying to add a ManagementPolicy (in golang) to an azure storage account. Unfortunately, it always fail because when I create it, it throw an error that the HTTP resource does not exist, which is true because it is not created. What am I doing wrong here? go.mod
Copy code
<http://github.com/pulumi/pulumi-azure-native-sdk/storage|github.com/pulumi/pulumi-azure-native-sdk/storage> v1.102.0
Copy code
import (
	"fmt"
	"<http://github.com/pulumi/pulumi-azure-native-sdk/storage|github.com/pulumi/pulumi-azure-native-sdk/storage>"
	"<http://github.com/pulumi/pulumi/sdk/v3/go/pulumi|github.com/pulumi/pulumi/sdk/v3/go/pulumi>"
	"<http://github.com/pulumi/pulumi/sdk/v3/go/pulumi/config|github.com/pulumi/pulumi/sdk/v3/go/pulumi/config>"
	"strings"
)

_, err := storage.NewManagementPolicy(ctx,
			fmt.Sprintf("%v-management-policy",
				storageAccountNamePulumi),
			&storage.ManagementPolicyArgs{
				AccountName:          storageAccount.Name,
				ResourceGroupName:    pulumi.String(sa.ResourceGroupName),
				ManagementPolicyName: pulumi.String("delete"),
				Policy: &storage.ManagementPolicySchemaArgs{
					Rules: &storage.ManagementPolicyRuleArray{
						&storage.ManagementPolicyRuleArgs{
							Enabled: pulumi.Bool(true),
							Name:    pulumi.String("DeleteRule"),
							Type:    pulumi.String("Lifecycle"),
							Definition: &storage.ManagementPolicyDefinitionArgs{
								Actions: &storage.ManagementPolicyActionArgs{
									Version: &storage.ManagementPolicyVersionArgs{
										Delete: &storage.DateAfterCreationArgs{
											DaysAfterCreationGreaterThan: pulumi.Float64(30),
										},
									},
								},
							},
						},
					},
				},
			},
			pulumi.Parent(storageAccount),
Output:
Copy code
+      └─ azure-native:storage:ManagementPolicy  infra-poc-dev-storage-account-files-management-policy  **creating failed**     1 error


Diagnostics:
  azure-native:storage:ManagementPolicy (infra-poc-dev-storage-account-files-management-policy):
    error: autorest/azure: Service returned an error. Status=404 Code="HttpResourceNotFound" Message="The request url <https://management.azure.com/subscriptions/25bdf887-1695-4563-bdeb-bb568e0246c8/resourceGroups/infra-poc-dev/providers/Microsoft.Storage/storageAccounts/infrapocdevfiles/managementPolicies/delete?api-version=2021-02-01> is not found."
Thanks :)
l

limited-rainbow-51650

05/08/2023, 9:40 AM
According the Microsoft Azure docs, the
ManagementPolicyName
should always be the value `default`: https://learn.microsoft.com/en-us/rest/api/storagerp/management-policies/create-or-update?tabs=HTTP#uri-parameters We copied that over to our Pulumi docs.
4 Views