Skip to content

Commit

Permalink
Merge pull request #1255 from hashicorp/private-vcs/api-support
Browse files Browse the repository at this point in the history
create oauth_client with agent pool
  • Loading branch information
zainq11 committed May 30, 2024
2 parents 933f36f + 348544e commit 385b5b1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ENHANCEMENTS:
* `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)
* `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)
* `r/tfe_registry_module`: Add `initial_version` support for Branch Based Modules by @aaabdelgany [#1363](https://github.com/hashicorp/terraform-provider-tfe/pull/1363)
* `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)

BUG FIXES:
* `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)
Expand Down
10 changes: 8 additions & 2 deletions internal/provider/resource_tfe_oauth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,15 @@ func resourceTFEOAuthClient() *schema.Resource {
false,
),
},

"oauth_token_id": {
Type: schema.TypeString,
Computed: true,
},

"agent_pool_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"organization_scoped": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -165,6 +168,9 @@ func resourceTFEOAuthClientCreate(d *schema.ResourceData, meta interface{}) erro
if serviceProvider == tfe.ServiceProviderBitbucket {
options.Secret = tfe.String(secret)
}
if v, ok := d.GetOk("agent_pool_id"); ok && v.(string) != "" {
options.AgentPool = &tfe.AgentPool{ID: *tfe.String(v.(string))}
}

log.Printf("[DEBUG] Create an OAuth client for organization: %s", organization)
oc, err := config.Client.OAuthClients.Create(ctx, organization, options)
Expand Down
47 changes: 47 additions & 0 deletions internal/provider/resource_tfe_oauth_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,32 @@ func TestAccTFEOAuthClient_rsaKeys(t *testing.T) {
})
}

func TestAccTFEOAuthClient_agentPool(t *testing.T) {
skipUnlessBeta(t)
oc := &tfe.OAuthClient{}
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
if envGithubToken == "" {
t.Skip("Please set GITHUB_TOKEN to run this test")
}
},
Providers: testAccProviders,
CheckDestroy: testAccCheckTFEOAuthClientDestroy,
Steps: []resource.TestStep{
{
Config: testAccTFEOAuthClient_agentPool(),
Check: resource.ComposeTestCheckFunc(
testAccCheckTFEOAuthClientExists("tfe_oauth_client.foobar", oc),
testAccCheckTFEOAuthClientAttributes(oc),
resource.TestCheckResourceAttr(
"tfe_oauth_client.foobar", "service_provider", "github_enterprise"),
),
},
},
})
}

func testAccCheckTFEOAuthClientExists(
n string, oc *tfe.OAuthClient) resource.TestCheckFunc {
return func(s *terraform.State) error {
Expand Down Expand Up @@ -217,3 +243,24 @@ hwIDAQAB
EOT
}`, rInt)
}

func testAccTFEOAuthClient_agentPool() string {
return fmt.Sprintf(`
data "tfe_organization" "foobar" {
name = "xxx"
}
data "tfe_agent_pool" "foobar" {
name = "xxx"
organization = data.tfe_organization.foobar.name
}
resource "tfe_oauth_client" "foobar" {
organization = data.tfe_organization.foobar.name
api_url = "https://githubenterprise.xxx/api/v3"
http_url = "https://githubenterprise.xxx"
oauth_token = "%s"
service_provider = "github_enterprise"
agent_pool_id = data.tfe_agent_pool.foobar.id
}`, envGithubToken)
}
1 change: 1 addition & 0 deletions website/docs/r/oauth_client.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Link.
* `service_provider` - (Required) The VCS provider being connected with. Valid
options are `ado_server`, `ado_services`, `bitbucket_data_center`, `bitbucket_hosted`, `bitbucket_server`(deprecated), `github`, `github_enterprise`, `gitlab_hosted`,
`gitlab_community_edition`, or `gitlab_enterprise_edition`.
* `agent_pool_id` - (Optional) An existing Agent pool id within the organization which has Private VCS support enabled via Premium SKU.
* `organization_scoped` - (Optional) Whether or not the oauth client is scoped to all projects and workspaces in the organization. Defaults to `true`.

## Attributes Reference
Expand Down

0 comments on commit 385b5b1

Please sign in to comment.