in pkg/deploy/lattice/service_network_manager.go [43:86]
func (m *defaultServiceNetworkManager) UpsertVpcAssociation(ctx context.Context, snName string, sgIds []*string) (string, error) {
sn, err := m.cloud.Lattice().FindServiceNetwork(ctx, snName)
if err != nil {
return "", err
}
snva, err := m.getActiveVpcAssociation(ctx, *sn.SvcNetwork.Id)
if err != nil {
return "", err
}
if snva != nil {
// association is active
owned, err := m.cloud.TryOwn(ctx, *snva.Arn)
if err != nil {
return "", err
}
if !owned {
return "", services.NewConflictError("snva", snName,
fmt.Sprintf("Found existing vpc association not owned by controller: %s", *snva.Arn))
}
_, err = m.updateServiceNetworkVpcAssociation(ctx, &sn.SvcNetwork, sgIds, snva.Id)
if err != nil {
return "", err
}
return *snva.Arn, nil
} else {
req := vpclattice.CreateServiceNetworkVpcAssociationInput{
ServiceNetworkIdentifier: sn.SvcNetwork.Id,
VpcIdentifier: &config.VpcID,
SecurityGroupIds: sgIds,
Tags: m.cloud.DefaultTags(),
}
resp, err := m.cloud.Lattice().CreateServiceNetworkVpcAssociationWithContext(ctx, &req)
if err != nil {
return "", err
}
switch status := aws.StringValue(resp.Status); status {
case vpclattice.ServiceNetworkVpcAssociationStatusActive:
return *resp.Arn, nil
default:
return *resp.Arn, fmt.Errorf("%w, vpc association status in %s", RetryErr, status)
}
}
}