-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from silinternational/develop
Release 3.2.0 - clone variable sets
- Loading branch information
Showing
4 changed files
with
183 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright © 2023 SIL International | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/silinternational/tfc-ops/lib" | ||
) | ||
|
||
var varsetsListCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "List Variable Sets", | ||
Long: `List variable sets applied to a workspace`, | ||
Args: cobra.ExactArgs(0), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
runVarsetsList() | ||
}, | ||
} | ||
|
||
func init() { | ||
varsetsCmd.AddCommand(varsetsListCmd) | ||
|
||
varsetsListCmd.Flags().StringVarP(&workspace, "workspace", "w", "", | ||
"Name of the Workspace in Terraform Cloud") | ||
|
||
varsetsListCmd.Flags().StringVar(&workspaceFilter, "workspace-filter", "", | ||
"Partial workspace name to search across all workspaces") | ||
} | ||
|
||
func runVarsetsList() { | ||
if workspace == "" && workspaceFilter == "" { | ||
errLog.Fatalln("Either --workspace or --workspace-filter must be specified.") | ||
} | ||
|
||
var workspaces map[string]string | ||
if workspace != "" { | ||
w, err := lib.GetWorkspaceByName(organization, workspace) | ||
if err != nil { | ||
errLog.Fatalf("error getting workspace %q from Terraform: %s", workspace, err) | ||
} | ||
workspaces = map[string]string{w.ID: workspace} | ||
} else { | ||
workspaces = lib.FindWorkspaces(organization, workspaceFilter) | ||
if len(workspaces) == 0 { | ||
errLog.Fatalf("no workspaces match the filter '%s'", workspaceFilter) | ||
} | ||
} | ||
|
||
for id, name := range workspaces { | ||
sets, err := lib.ListWorkspaceVariableSets(id) | ||
if err != nil { | ||
return | ||
} | ||
fmt.Printf("Workspace %s has the following variable sets:\n", name) | ||
for _, set := range sets.Data { | ||
fmt.Printf(" %s\n", set.Attributes.Name) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters