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 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
github.com/hashicorp/go-slug v0.14.0
github.com/hashicorp/go-tfe v1.45.0
github.com/hashicorp/go-tfe v1.46.0
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/hcl/v2 v2.19.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT
github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/hashicorp/go-slug v0.14.0 h1:/aZdUDjR74TSlsQp3hA9nqhCQkQHAUr2jjtuUfWqI9E=
github.com/hashicorp/go-slug v0.14.0/go.mod h1:THWVTAXwJEinbsp4/bBRcmbaO5EYNLTqxbG4tZ3gCYQ=
github.com/hashicorp/go-tfe v1.45.0 h1:WCiQWUV7n1Fq/pKA9C3rhcSmUtSPTYBtE1kIJ9U0NSU=
github.com/hashicorp/go-tfe v1.45.0/go.mod h1:GRvhVp0mlNK/msPAvdeubWnV57avNoCmeaetcmvUyHY=
github.com/hashicorp/go-tfe v1.46.0 h1:IlFh96QoC9wYag8LR7J9g0iEILWPpZ+BTqTzABvBax8=
github.com/hashicorp/go-tfe v1.46.0/go.mod h1:GRvhVp0mlNK/msPAvdeubWnV57avNoCmeaetcmvUyHY=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
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)
}
Loading