func()

in pkg/aws/services/vpclattice.go [363:405]


func (d *defaultLattice) FindServiceNetwork(ctx context.Context, nameOrId string) (*ServiceNetworkInfo, error) {
	// When default service network is provided, override for any kind of SN search
	if config.ServiceNetworkOverrideMode {
		nameOrId = config.DefaultServiceNetwork
	}

	input := &vpclattice.ListServiceNetworksInput{}
	allSn, err := d.ListServiceNetworksAsList(ctx, input)
	if err != nil {
		return nil, err
	}

	snMatch, err := d.serviceNetworkMatch(allSn, nameOrId)
	if err != nil {
		return nil, err
	}

	// try to fetch tags only if SN in the same aws account with controller's config
	tags := Tags{}
	isLocal, err := d.isLocalResource(aws.StringValue(snMatch.Arn))
	if err != nil {
		return nil, err
	}
	if isLocal {
		tagsInput := vpclattice.ListTagsForResourceInput{ResourceArn: snMatch.Arn}
		tagsOutput, err := d.ListTagsForResourceWithContext(ctx, &tagsInput)
		if err != nil {
			aerr, ok := err.(awserr.Error)
			// In case ownAccount is not set, we cant tell if SN is foreign.
			// In this case access denied is expected.
			if !ok || aerr.Code() != vpclattice.ErrCodeAccessDeniedException {
				return nil, err
			}
		} else {
			tags = tagsOutput.Tags
		}
	}

	return &ServiceNetworkInfo{
		SvcNetwork: *snMatch,
		Tags:       tags,
	}, nil
}