func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error {
	nsgSpec, ok := spec.(*Spec)
	if !ok {
		return errors.New("invalid security groups specification")
	}

	securityRules := &[]network.SecurityRule{}

	if nsgSpec.IsControlPlane {
		klog.V(2).Infof("using additional rules for control plane %s", nsgSpec.Name)
		securityRules = &[]network.SecurityRule{
			{
				Name: to.StringPtr("allow_ssh"),
				SecurityRulePropertiesFormat: &network.SecurityRulePropertiesFormat{
					Protocol:                 network.SecurityRuleProtocolTCP,
					SourceAddressPrefix:      to.StringPtr("*"),
					SourcePortRange:          to.StringPtr("*"),
					DestinationAddressPrefix: to.StringPtr("*"),
					DestinationPortRange:     to.StringPtr("22"),
					Access:                   network.SecurityRuleAccessAllow,
					Direction:                network.SecurityRuleDirectionInbound,
					Priority:                 to.Int32Ptr(100),
				},
			},
			{
				Name: to.StringPtr("allow_6443"),
				SecurityRulePropertiesFormat: &network.SecurityRulePropertiesFormat{
					Protocol:                 network.SecurityRuleProtocolTCP,
					SourceAddressPrefix:      to.StringPtr("*"),
					SourcePortRange:          to.StringPtr("*"),
					DestinationAddressPrefix: to.StringPtr("*"),
					DestinationPortRange:     to.StringPtr("6443"),
					Access:                   network.SecurityRuleAccessAllow,
					Direction:                network.SecurityRuleDirectionInbound,
					Priority:                 to.Int32Ptr(101),
				},
			},
		}
	}

	klog.V(2).Infof("creating security group %s", nsgSpec.Name)
	f, err := s.Client.CreateOrUpdate(
		ctx,
		s.Scope.MachineConfig.ResourceGroup,
		nsgSpec.Name,
		network.SecurityGroup{
			Location: to.StringPtr(s.Scope.MachineConfig.Location),
			SecurityGroupPropertiesFormat: &network.SecurityGroupPropertiesFormat{
				SecurityRules: securityRules,
			},
		},
	)
	if err != nil {
		return fmt.Errorf("failed to create security group %s in resource group %s: %w", nsgSpec.Name, s.Scope.MachineConfig.ResourceGroup, err)
	}

	err = f.WaitForCompletionRef(ctx, s.Client.Client)
	if err != nil {
		return fmt.Errorf("cannot create, future response: %w", err)
	}

	_, err = f.Result(s.Client)
	if err != nil {
		return fmt.Errorf("result error: %w", err)
	}
	klog.V(2).Infof("created security group %s", nsgSpec.Name)
	return err
}
// CreateOrUpdate creates or updates a route table.
CreateOrUpdate creates or updates a route table.
// CreateOrUpdate creates or updates a route table .
func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error {
	nsgSpec, ok := spec.(*Spec)
	if !ok {
		return errors.New("invalid security groups specification")
	}
	securityRules := &[]network.SecurityRule{}
	if nsgSpec.IsControlPlane {
		klog.V(2).Infof("using additional rules for control plane %s", nsgSpec.Name)
		securityRules = &[]network.SecurityRule{
			{
				Name: to.StringPtr("allow_ssh"),
				SecurityRulePropertiesFormat: &network.SecurityRulePropertiesFormat{
					Protocol:                 network.SecurityRuleProtocolTCP,
					SourceAddressPrefix:      to.StringPtr("*"),
					SourcePortRange:          to.StringPtr("*"),
					DestinationAddressPrefix: to.StringPtr("*"),
					DestinationPortRange:     to.StringPtr("22"),
					Access:                   network.SecurityRuleAccessAllow,
					Direction:                network.SecurityRuleDirectionInbound,
					Priority:                 to.Int32Ptr(100),
				},
			},
			{
				Name: to.StringPtr("allow_6443"),
				SecurityRulePropertiesFormat: &network.SecurityRulePropertiesFormat{
					Protocol:                 network.SecurityRuleProtocolTCP,
					SourceAddressPrefix:      to.StringPtr("*"),
					SourcePortRange:          to.StringPtr("*"),
					DestinationAddressPrefix: to.StringPtr("*"),
					DestinationPortRange:     to.StringPtr("6443"),
					Access:                   network.SecurityRuleAccessAllow,
					Direction:                network.SecurityRuleDirectionInbound,
					Priority:                 to.Int32Ptr(101),
				},
			},
		}
	}
	klog.V(2).Infof("creating security group %s", nsgSpec.Name)
	f, err := s.Client.CreateOrUpdate(
		ctx,
		s.Scope.MachineConfig.ResourceGroup,
		nsgSpec.Name,
		network.SecurityGroup{
			Location: to.StringPtr(s.Scope.MachineConfig.Location),
			SecurityGroupPropertiesFormat: &network.SecurityGroupPropertiesFormat{
				SecurityRules: securityRules,
			},
		},
	)
	if err != nil {
		return fmt.Errorf("failed to create security group %s in resource group %s: %w", nsgSpec.Name, s.Scope.MachineConfig.ResourceGroup, err)
	}
	err = f.WaitForCompletionRef(ctx, s.Client.Client)
	if err != nil {
		return fmt.Errorf("cannot create, future response: %w", err)
	}
	_, err = f.Result(s.Client)
	if err != nil {
		return fmt.Errorf("result error: %w", err)
	}
	klog.V(2).Infof("created security group %s", nsgSpec.Name)
	return err
}
func ( s * Service ) CreateOrUpdate ( ctx context . Context , spec azure . Spec ) error { nsgSpec , ok := spec . ( * Spec ) if ! ok { return errors . New ( " " ) } securityRules := & [ ] network . SecurityRule { } if nsgSpec . IsControlPlane { klog . V ( 2 ) . Infof ( " " , nsgSpec . Name ) securityRules = & [ ] network . SecurityRule { { Name : to . StringPtr ( " " ) , SecurityRulePropertiesFormat : & network . SecurityRulePropertiesFormat { Protocol : network . SecurityRuleProtocolTCP , SourceAddressPrefix : to . StringPtr ( " " ) , SourcePortRange : to . StringPtr ( " " ) , DestinationAddressPrefix : to . StringPtr ( " " ) , DestinationPortRange : to . StringPtr ( " " ) , Access : network . SecurityRuleAccessAllow , Direction : network . SecurityRuleDirectionInbound , Priority : to . Int32Ptr ( 100 ) , } , } , { Name : to . StringPtr ( " " ) , SecurityRulePropertiesFormat : & network . SecurityRulePropertiesFormat { Protocol : network . SecurityRuleProtocolTCP , SourceAddressPrefix : to . StringPtr ( " " ) , SourcePortRange : to . StringPtr ( " " ) , DestinationAddressPrefix : to . StringPtr ( " " ) , DestinationPortRange : to . StringPtr ( " " ) , Access : network . SecurityRuleAccessAllow , Direction : network . SecurityRuleDirectionInbound , Priority : to . Int32Ptr ( 101 ) , } , } , } } klog . V ( 2 ) . Infof ( " " , nsgSpec . Name ) f , err := s . Client . CreateOrUpdate ( ctx , s . Scope . MachineConfig . ResourceGroup , nsgSpec . Name , network . SecurityGroup { Location : to . StringPtr ( s . Scope . MachineConfig . Location ) , SecurityGroupPropertiesFormat : & network . SecurityGroupPropertiesFormat { SecurityRules : securityRules , } , } , ) if err != nil { return fmt . Errorf ( " " , nsgSpec . Name , s . Scope . MachineConfig . ResourceGroup , err ) } err = f . WaitForCompletionRef ( ctx , s . Client . Client ) if err != nil { return fmt . Errorf ( " " , err ) } _ , err = f . Result ( s . Client ) if err != nil { return fmt . Errorf ( " " , err ) } klog . V ( 2 ) . Infof ( " " , nsgSpec . Name ) return err }
CreateOrUpdate creates or updates a route table.
CreateOrUpdate creates or updates a route table .