-
Notifications
You must be signed in to change notification settings - Fork 155
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 #561 from hashicorp/jspiker/import-pool-by-name
Allow agent pools to be imported by name
- Loading branch information
Showing
6 changed files
with
81 additions
and
33 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,38 @@ | ||
package tfe | ||
|
||
import ( | ||
"fmt" | ||
|
||
tfe "github.com/hashicorp/go-tfe" | ||
) | ||
|
||
func fetchAgentPoolID(orgName string, poolName string, client *tfe.Client) (string, error) { | ||
// to reduce the number of pages returned, search based on the name. TFE instances which | ||
// do not support agent pool search will just ignore the query parameter | ||
options := tfe.AgentPoolListOptions{ | ||
Query: poolName, | ||
} | ||
|
||
for { | ||
l, err := client.AgentPools.List(ctx, orgName, &options) | ||
if err != nil { | ||
return "", fmt.Errorf("Error retrieving agent pools: %w", err) | ||
} | ||
|
||
for _, k := range l.Items { | ||
if k.Name == poolName { | ||
return k.ID, nil | ||
} | ||
} | ||
|
||
// Exit the loop when we've seen all pages. | ||
if l.CurrentPage >= l.TotalPages { | ||
break | ||
} | ||
|
||
// Update the page number to get the next page. | ||
options.PageNumber = l.NextPage | ||
} | ||
|
||
return "", tfe.ErrResourceNotFound | ||
} |
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
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