Skip to content

Commit 385b5b1

Browse files
authored
Merge pull request #1255 from hashicorp/private-vcs/api-support
create oauth_client with agent pool
2 parents 933f36f + 348544e commit 385b5b1

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ENHANCEMENTS:
55
* `r/tfe_workspace`: Add an `auto_destroy_at` attribute for scheduling an auto-destroy run in the future, by @notchairmk [1354](https://github.com/hashicorp/terraform-provider-tfe/pull/1354)
66
* `d/tfe_workspace`: Add an `auto_destroy_at` attribute for reading a scheduled auto-destroy, by @notchairmk [1354](https://github.com/hashicorp/terraform-provider-tfe/pull/1354)
77
* `r/tfe_registry_module`: Add `initial_version` support for Branch Based Modules by @aaabdelgany [#1363](https://github.com/hashicorp/terraform-provider-tfe/pull/1363)
8+
* `r/tfe_oauth_client`: Add `agent_pool_id` as an optional argument to enable Private VCS support, by @roleesinhaHC [1255](https://github.com/hashicorp/terraform-provider-tfe/pull/1255)
89

910
BUG FIXES:
1011
* `r/tfe_registry_module`: Prevents constant diff after a successful apply when `tags` and `tests_enabled` is not set by @Uk1288 [#1357](https://github.com/hashicorp/terraform-provider-tfe/pull/1357)

internal/provider/resource_tfe_oauth_client.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,15 @@ func resourceTFEOAuthClient() *schema.Resource {
108108
false,
109109
),
110110
},
111-
112111
"oauth_token_id": {
113112
Type: schema.TypeString,
114113
Computed: true,
115114
},
116-
115+
"agent_pool_id": {
116+
Type: schema.TypeString,
117+
Optional: true,
118+
Computed: true,
119+
},
117120
"organization_scoped": {
118121
Type: schema.TypeBool,
119122
Optional: true,
@@ -165,6 +168,9 @@ func resourceTFEOAuthClientCreate(d *schema.ResourceData, meta interface{}) erro
165168
if serviceProvider == tfe.ServiceProviderBitbucket {
166169
options.Secret = tfe.String(secret)
167170
}
171+
if v, ok := d.GetOk("agent_pool_id"); ok && v.(string) != "" {
172+
options.AgentPool = &tfe.AgentPool{ID: *tfe.String(v.(string))}
173+
}
168174

169175
log.Printf("[DEBUG] Create an OAuth client for organization: %s", organization)
170176
oc, err := config.Client.OAuthClients.Create(ctx, organization, options)

internal/provider/resource_tfe_oauth_client_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,32 @@ func TestAccTFEOAuthClient_rsaKeys(t *testing.T) {
108108
})
109109
}
110110

111+
func TestAccTFEOAuthClient_agentPool(t *testing.T) {
112+
skipUnlessBeta(t)
113+
oc := &tfe.OAuthClient{}
114+
resource.Test(t, resource.TestCase{
115+
PreCheck: func() {
116+
testAccPreCheck(t)
117+
if envGithubToken == "" {
118+
t.Skip("Please set GITHUB_TOKEN to run this test")
119+
}
120+
},
121+
Providers: testAccProviders,
122+
CheckDestroy: testAccCheckTFEOAuthClientDestroy,
123+
Steps: []resource.TestStep{
124+
{
125+
Config: testAccTFEOAuthClient_agentPool(),
126+
Check: resource.ComposeTestCheckFunc(
127+
testAccCheckTFEOAuthClientExists("tfe_oauth_client.foobar", oc),
128+
testAccCheckTFEOAuthClientAttributes(oc),
129+
resource.TestCheckResourceAttr(
130+
"tfe_oauth_client.foobar", "service_provider", "github_enterprise"),
131+
),
132+
},
133+
},
134+
})
135+
}
136+
111137
func testAccCheckTFEOAuthClientExists(
112138
n string, oc *tfe.OAuthClient) resource.TestCheckFunc {
113139
return func(s *terraform.State) error {
@@ -217,3 +243,24 @@ hwIDAQAB
217243
EOT
218244
}`, rInt)
219245
}
246+
247+
func testAccTFEOAuthClient_agentPool() string {
248+
return fmt.Sprintf(`
249+
data "tfe_organization" "foobar" {
250+
name = "xxx"
251+
}
252+
253+
data "tfe_agent_pool" "foobar" {
254+
name = "xxx"
255+
organization = data.tfe_organization.foobar.name
256+
}
257+
258+
resource "tfe_oauth_client" "foobar" {
259+
organization = data.tfe_organization.foobar.name
260+
api_url = "https://githubenterprise.xxx/api/v3"
261+
http_url = "https://githubenterprise.xxx"
262+
oauth_token = "%s"
263+
service_provider = "github_enterprise"
264+
agent_pool_id = data.tfe_agent_pool.foobar.id
265+
}`, envGithubToken)
266+
}

website/docs/r/oauth_client.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Link.
9090
* `service_provider` - (Required) The VCS provider being connected with. Valid
9191
options are `ado_server`, `ado_services`, `bitbucket_data_center`, `bitbucket_hosted`, `bitbucket_server`(deprecated), `github`, `github_enterprise`, `gitlab_hosted`,
9292
`gitlab_community_edition`, or `gitlab_enterprise_edition`.
93+
* `agent_pool_id` - (Optional) An existing Agent pool id within the organization which has Private VCS support enabled via Premium SKU.
9394
* `organization_scoped` - (Optional) Whether or not the oauth client is scoped to all projects and workspaces in the organization. Defaults to `true`.
9495

9596
## Attributes Reference

0 commit comments

Comments
 (0)