Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create oauth_client with agent pool #1255

Merged
merged 15 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

FEATURES:
* `r/tfe_workspace`: Add `ignore_additional_tag_names` which explicitly ignores `tag_names` _not_ defined by config so they will not be overwritten by the configured tags, by @brandonc and @mbillow [1254](https://github.com/hashicorp/terraform-provider-tfe/pull/1254)
* `r/tfe_oauth_client`: Add `agent_pool_id` as an optional argument to enable Private VCS support, by @rolee.sinha [1255](https://github.com/hashicorp/terraform-provider-tfe/pull/1255)

BUG FIXES:

Expand Down
9 changes: 9 additions & 0 deletions internal/provider/resource_tfe_oauth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ func resourceTFEOAuthClient() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"agent_pool_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -156,6 +162,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 @@ -75,6 +75,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 @@ -183,3 +209,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 @@ -89,6 +89,7 @@ Link.
* `service_provider` - (Required) The VCS provider being connected with. Valid
options are `ado_server`, `ado_services`, `bitbucket_hosted`, `bitbucket_server`, `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.

## Attributes Reference

Expand Down