# WithNetworkSecurityPerimeter

- Module: [Aspire.Hosting.Azure.Network](/reference/api/go/aspire.hosting.azure.network.md)
- Version: `17.0.0`
- Kind: `method`
- Defined on: `Resource`
- Source: [GitHub](https://github.com/microsoft/aspire/tree/2d325b13709752ba6d9a943635c5e2940a2530c0)

Associates an Azure PaaS resource with a Network Security Perimeter.

## Remarks

In `Enforced` mode, resources within the
perimeter can communicate with each other, but public access is restricted to the rules defined
in the perimeter profile.
In `Learning` mode, traffic that would
be blocked by the perimeter rules is logged but not denied. This is useful when onboarding
resources to identify required access rules before switching to enforced mode.

## Definition

```go
func (Resource) WithNetworkSecurityPerimeter(
    nsp AzureNetworkSecurityPerimeterResource,
    options ...*WithNetworkSecurityPerimeterOptions,
) Resource
```

## Parameters

- `nsp` ([`AzureNetworkSecurityPerimeterResource`](/reference/api/go/aspire.hosting.azure.network/azurenetworksecurityperimeterresource.md)) -- The Network Security Perimeter to associate with.
- `options` (`...*WithNetworkSecurityPerimeterOptions`) -- optional settings, see [Options](#options)

## Options

Optional parameters are passed in a trailing `options ...*WithNetworkSecurityPerimeterOptions` argument.

- `AccessMode` (`*NetworkSecurityPerimeterAssociationAccessMode`) -- The access mode for the association. Defaults to `Enforced`. Use `Learning` to log violations without blocking traffic.
- `AssociationName` (`*string`) -- An optional name for the association. If not provided, defaults to `"{resourceName}-assoc"`.

## Returns

`Resource` -- A reference to the target resource builder for chaining.

Returns a handle; failures surface later via `Err()`.

## Applies to

- [`AzureBicepResource`](/reference/api/go/aspire.hosting.azure.network/azurebicepresource.md)
- [`AzureEnvironmentResource`](/reference/api/go/aspire.hosting.azure.network/azureenvironmentresource.md)
- [`AzureNatGatewayResource`](/reference/api/go/aspire.hosting.azure.network/azurenatgatewayresource.md)
- [`AzureNetworkSecurityGroupResource`](/reference/api/go/aspire.hosting.azure.network/azurenetworksecuritygroupresource.md)
- [`AzureNetworkSecurityPerimeterResource`](/reference/api/go/aspire.hosting.azure.network/azurenetworksecurityperimeterresource.md)
- [`AzurePrivateEndpointResource`](/reference/api/go/aspire.hosting.azure.network/azureprivateendpointresource.md)
- [`AzureProvisioningResource`](/reference/api/go/aspire.hosting.azure.network/azureprovisioningresource.md)
- [`AzurePublicIPAddressResource`](/reference/api/go/aspire.hosting.azure.network/azurepublicipaddressresource.md)
- [`AzureSubnetResource`](/reference/api/go/aspire.hosting.azure.network/azuresubnetresource.md)
- [`AzureUserAssignedIdentityResource`](/reference/api/go/aspire.hosting.azure.network/azureuserassignedidentityresource.md)
- [`AzureVirtualNetworkResource`](/reference/api/go/aspire.hosting.azure.network/azurevirtualnetworkresource.md)
- `CSharpAppResource`
- `ContainerRegistryResource`
- `ContainerResource`
- `DotnetToolResource`
- `ExecutableResource`
- `ExternalServiceResource`
- `ParameterResource`
- `ProjectResource`
