Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions resourcemanager/commonschema/public_network_access.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package commonschema

import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/network"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

// PublicNetworkAccessOptional returns the schema for a `public_network_access` field that is Optional.
func PublicNetworkAccessOptional(supportsSecuredByPerimeter bool) *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: string(network.PublicNetworkAccessEnabled),
ValidateFunc: validationFunctionForPublicNetworkAccess(supportsSecuredByPerimeter),
}
}

// PublicNetworkAccessOptionalForceNew returns the schema for a `public_network_access` field that
// is both Optional and ForceNew.
func PublicNetworkAccessOptionalForceNew(supportsSecuredByPerimeter bool) *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: string(network.PublicNetworkAccessEnabled),
ForceNew: true,
ValidateFunc: validationFunctionForPublicNetworkAccess(supportsSecuredByPerimeter),
}
}

// PublicNetworkAccessRequired returns the schema for a `public_network_access` field that is Required.
func PublicNetworkAccessRequired(supportsSecuredByPerimeter bool) *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Required: true,
ValidateFunc: validationFunctionForPublicNetworkAccess(supportsSecuredByPerimeter),
}
}

// PublicNetworkAccessRequiredForceNew returns the schema for a `public_network_access` field that
// is both Required and ForceNew.
func PublicNetworkAccessRequiredForceNew(supportsSecuredByPerimeter bool) *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validationFunctionForPublicNetworkAccess(supportsSecuredByPerimeter),
}
}

// validationFunctionForPublicNetworkAccess returns the validation function for the `public_network_access` field
func validationFunctionForPublicNetworkAccess(supportsSecuredByPerimeter bool) schema.SchemaValidateFunc {
if supportsSecuredByPerimeter {
return validation.StringInSlice([]string{
string(network.PublicNetworkAccessDisabled),
string(network.PublicNetworkAccessEnabled),
string(network.PublicNetworkAccessSecuredByPerimeter),
}, false)
}

return validation.StringInSlice([]string{
string(network.PublicNetworkAccessDisabled),
string(network.PublicNetworkAccessEnabled),
}, false)
}
20 changes: 20 additions & 0 deletions resourcemanager/network/public_network_access.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package network

// PublicNetworkAccess specifies whether a given Azure Resource is publicly accessible (fully/partially) or
// private.
type PublicNetworkAccess string

const (
// PublicNetworkAccessDisabled specifies that Public Network Access is Disabled.
PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled"

// PublicNetworkAccessEnabled specifies that Public Network Access is Enabled.
PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled"

// PublicNetworkAccessSecuredByPerimeter specifies that Public Network Access is controlled by
// the Network Security Perimeter.
PublicNetworkAccessSecuredByPerimeter PublicNetworkAccess = "SecuredByPerimeter"
)