func enableAPI(api string) error {
	cg, err := getCommandGroupByVersion(smChangeVersion, oldSMCommandGroup, newSMCommandGroup)
	if err != nil {
		return fmt.Errorf("error retrieving command group for Service Management: %v", err)
	}
	cmd := exec.Command("gcloud", cg, "enable", api)
	_, err = cmd.CombinedOutput()
	if err != nil {
		return fmt.Errorf("failed to enable API %s : %v", api, err)
	}
	return nil
}
enableAPI enables a GCP API.
package gcp
import (
	"encoding/json"
	"fmt"
	"os/exec"
	"strconv"
	"strings"
	"time"
)
const (
	oldSMCommandGroup = "service-management"
	newSMCommandGroup = "services"
	smChangeVersion   = "188.0.0"
)
func EnableAPIs(apis []string) error {
	existingAPIs, err := enabledAPIs()
	if err != nil {
		return err
	}
	for _, api := range apis {
		if _, found := existingAPIs[api]; !found {
			fmt.Printf("enabling a GCP API: %s\n", api)
			err = enableAPI(api)
			if err != nil {
				return err
			}
		}
	}
	return nil
}
func enabledAPIs() (map[string]bool, error) {
	cg, err := getCommandGroupByVersion(smChangeVersion, oldSMCommandGroup, newSMCommandGroup)
	if err != nil {
		return nil, fmt.Errorf("error retrieving command group for Service Management: %v", err)
	}
	cmd := exec.Command("gcloud", cg, "list", "--format", "json")
	output, err := cmd.Output()
	if err != nil {
		return nil, fmt.Errorf("failed to retrieve enabled GCP APIs : %v", err)
	}
	var apis []gcpAPI
	err = json.Unmarshal(output, &apis)
	if err != nil {
		return nil, fmt.Errorf("failed to parse enabled API response : %v", err)
	}
	m := make(map[string]bool, len(apis))
	for _, api := range apis {
		m[api.ServiceName] = true
	}
	return m, nil
}
type gcpAPI struct {
	ServiceName string `json:"serviceName"`
}