sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/services/vnetpeerings/spec.go (about) 1 /* 2 Copyright 2021 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package vnetpeerings 18 19 import ( 20 "context" 21 22 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v4" 23 "github.com/pkg/errors" 24 "k8s.io/utils/ptr" 25 "sigs.k8s.io/cluster-api-provider-azure/azure" 26 ) 27 28 // VnetPeeringSpec defines the specification for a virtual network peering. 29 type VnetPeeringSpec struct { 30 SourceResourceGroup string 31 SourceVnetName string 32 RemoteResourceGroup string 33 RemoteVnetName string 34 PeeringName string 35 SubscriptionID string 36 AllowForwardedTraffic *bool 37 AllowGatewayTransit *bool 38 AllowVirtualNetworkAccess *bool 39 UseRemoteGateways *bool 40 } 41 42 // ResourceName returns the name of the virtual network peering. 43 func (s *VnetPeeringSpec) ResourceName() string { 44 return s.PeeringName 45 } 46 47 // ResourceGroupName returns the name of the resource group. 48 func (s *VnetPeeringSpec) ResourceGroupName() string { 49 return s.SourceResourceGroup 50 } 51 52 // OwnerResourceName is a no-op for virtual network peerings. 53 func (s *VnetPeeringSpec) OwnerResourceName() string { 54 return s.SourceVnetName 55 } 56 57 // Parameters returns the parameters for the virtual network peering. 58 func (s *VnetPeeringSpec) Parameters(ctx context.Context, existing interface{}) (params interface{}, err error) { 59 if existing != nil { 60 if _, ok := existing.(armnetwork.VirtualNetworkPeering); !ok { 61 return nil, errors.Errorf("%T is not an armnetwork.VnetPeering", existing) 62 } 63 // virtual network peering already exists 64 return nil, nil 65 } 66 vnetID := azure.VNetID(s.SubscriptionID, s.RemoteResourceGroup, s.RemoteVnetName) 67 peeringProperties := armnetwork.VirtualNetworkPeeringPropertiesFormat{ 68 RemoteVirtualNetwork: &armnetwork.SubResource{ 69 ID: ptr.To(vnetID), 70 }, 71 AllowForwardedTraffic: s.AllowForwardedTraffic, 72 AllowGatewayTransit: s.AllowGatewayTransit, 73 AllowVirtualNetworkAccess: s.AllowVirtualNetworkAccess, 74 UseRemoteGateways: s.UseRemoteGateways, 75 } 76 return armnetwork.VirtualNetworkPeering{ 77 Name: ptr.To(s.PeeringName), 78 Properties: &peeringProperties, 79 }, nil 80 }