{"record":{"id":"d9fb9f050c4b082c","repo":"kubernetes/kops","slug":"creating-updating-virtual-network-w","errorCode":null,"errorMessage":"creating/updating virtual network: %w","messagePattern":"creating/updating virtual network: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/azure/virtualnetwork.go","lineNumber":45,"sourceCode":")\n\n// VirtualNetworksClient is a client for managing Virtual Networks.\ntype VirtualNetworksClient interface {\n\tCreateOrUpdate(ctx context.Context, resourceGroupName, virtualNetworkName string, parameters network.VirtualNetwork) (*network.VirtualNetwork, error)\n\tList(ctx context.Context, resourceGroupName string) ([]*network.VirtualNetwork, error)\n\tDelete(ctx context.Context, resourceGroupName, vnetName string) error\n}\n\ntype virtualNetworksClientImpl struct {\n\tc *network.VirtualNetworksClient\n}\n\nvar _ VirtualNetworksClient = (*virtualNetworksClientImpl)(nil)\n\nfunc (c *virtualNetworksClientImpl) CreateOrUpdate(ctx context.Context, resourceGroupName, virtualNetworkName string, parameters network.VirtualNetwork) (*network.VirtualNetwork, error) {\n\tfuture, err := c.c.BeginCreateOrUpdate(ctx, resourceGroupName, virtualNetworkName, parameters, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"creating/updating virtual network: %w\", err)\n\t}\n\tvnet, err := future.PollUntilDone(ctx, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"waiting for virtual network create/update completion: %w\", err)\n\t}\n\treturn &vnet.VirtualNetwork, err\n}\n\nfunc (c *virtualNetworksClientImpl) List(ctx context.Context, resourceGroupName string) ([]*network.VirtualNetwork, error) {\n\tif resourceGroupName == \"\" {\n\t\treturn nil, nil\n\t}\n\n\tvar l []*network.VirtualNetwork\n\tpager := c.c.NewListPager(resourceGroupName, nil)\n\tfor pager.More() {\n\t\tresp, err := pager.NextPage(ctx)\n\t\tif err != nil {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/azure/virtualnetwork.go#L27-L63","documentation":"Wrapped when the initial BeginCreateOrUpdate call to the Azure VirtualNetworks client fails synchronously — i.e., the request never became a long-running future. The ARM error (invalid parameters, RBAC denial, name conflict, 4xx/5xx) is preserved by %w. It fires before the polling stage that produces the 'waiting for virtual network create/update completion' error.","triggerScenarios":"virtualNetworksClientImpl.CreateOrUpdate calls c.c.BeginCreateOrUpdate(ctx, resourceGroupName, virtualNetworkName, parameters, nil) and the SDK returns an error: invalid VirtualNetwork parameters (bad CIDR, DNS servers), missing networkContributor/write permission on the resource group, wrong resource group or vnet name, or network failure.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped azcore.ResponseError for StatusCode and ErrorCode to identify the ARM failure","Verify the service principal has Network Contributor (or Owner) on the resource group","Validate the VirtualNetwork parameters (addressSpace CIDRs, subnets, location) in the kops cluster spec","Ensure the resource group exists and the vnet name/location match the spec"],"exampleFix":"// before\nVirtualNetwork{ Location: to.Ptr(\"eastus\"), AddressSpace: ... } // CIDR overlaps existing vnet\n// after\nVirtualNetwork{ Location: to.Ptr(\"eastus\"), AddressSpace: &network.AddressSpace{AddressPrefixes: []*string{to.Ptr(\"172.16.0.0/12\")}} } // unique, non-overlapping CIDR","handlingStrategy":"try-catch","validationCode":"// Go: pre-validate vnet parameters before CreateOrUpdate\nif parameters.Location == nil || parameters.AddressSpace == nil || len(parameters.AddressSpace.AddressPrefixes) == 0 {\n    return fmt.Errorf(\"virtual network %s/%s missing location or address space\", resourceGroupName, virtualNetworkName)\n}\n// ensure resource group exists\nif _, err := rgClient.Get(ctx, resourceGroupName, nil); err != nil {\n    return fmt.Errorf(\"resource group %s not found: %w\", resourceGroupName, err)\n}","typeGuard":"func armDenied(err error) bool {\n    var respErr *azcore.ResponseError\n    return errors.As(err, &respErr) && (respErr.StatusCode == http.StatusForbidden || respErr.StatusCode == http.StatusUnauthorized)\n}","tryCatchPattern":"vnet, err := vnetsClient.CreateOrUpdate(ctx, rg, name, parameters)\nif err != nil {\n    var respErr *azcore.ResponseError\n    if errors.As(err, &respErr) {\n        switch {\n        case respErr.StatusCode == http.StatusForbidden:\n            return fmt.Errorf(\"grant Network Contributor on %s: %w\", rg, err)\n        case respErr.StatusCode == http.StatusConflict:\n            return fmt.Errorf(\"vnet %s already exists/CIDR conflict: %w\", name, err)\n        }\n    }\n    return err\n}","preventionTips":["Check the service principal's role assignment (Network Contributor) on the resource group before provisioning","Ensure vnet CIDRs in the cluster spec don't overlap existing networks","Create the resource group before the vnet","Handle 429 with retry-after using azruntime retry options"],"tags":["azure","go","network","vnet"],"backgroundTag":"azure-vnet-create-or-update-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}