You need to enable JavaScript to run this app.
导航

网络ACL关联子网

最近更新时间2023.08.29 19:07:29

首次发布时间2023.06.09 11:20:33

本文介绍如何为网络ACL关联子网。

示例代码

// Example Code generated by Beijing Volcanoengine Technology.

package vpcexample


import (
	"fmt"

	"github.com/volcengine/volcengine-go-sdk/service/vpc"
	"github.com/volcengine/volcengine-go-sdk/volcengine"
	"github.com/volcengine/volcengine-go-sdk/volcengine/credentials"
	"github.com/volcengine/volcengine-go-sdk/volcengine/session"
)

func AssociateNetworkAcl() {
  // 设置您的ak、sk、要访问的地域
	ak, sk, region := "Your AK", "Your SK", "Region"
	config := volcengine.NewConfig().
		WithRegion(region).
		WithCredentials(credentials.NewStaticCredentials(ak, sk, ""))
	sess, err := session.NewSession(config)
	if err != nil {
		panic(err)
	}
	svc := vpc.New(sess)

	// 待关联子网1
	reqResource0 := &vpc.ResourceForAssociateNetworkAclInput{
		ResourceId: volcengine.String("subnet-67acfmxazb4p****"), // 子网的ID
	}

	// 待关联子网2
	reqResource1 := &vpc.ResourceForAssociateNetworkAclInput{
		ResourceId: volcengine.String("subnet-g655nh68xyz9****"), // 子网的ID
	}

	// 为网络ACL关联子网
	associateNetworkAclInput := &vpc.AssociateNetworkAclInput{
		NetworkAclId: volcengine.String("nacl-bp1fg655nh68xyz9****"),  //网络ACL的ID
		Resource:     []*vpc.ResourceForAssociateNetworkAclInput{reqResource0, reqResource1}, // 待关联的子网
	}

  // 发起请求并处理返回或异常
	resp, err := svc.AssociateNetworkAcl(associateNetworkAclInput)
	if err != nil {
		panic(err)
	}
	fmt.Println(resp)

相关文档