Skip to content

Commit 83e97f8

Browse files
committed
create oauth_client with agent pool
1 parent 4c66c55 commit 83e97f8

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

internal/provider/resource_tfe_oauth_client.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ func resourceTFEOAuthClient() *schema.Resource {
111111
Type: schema.TypeString,
112112
Computed: true,
113113
},
114+
115+
"agent_pool_id": {
116+
Type: schema.TypeString,
117+
Optional: true,
118+
Computed: true,
119+
},
114120
},
115121
}
116122
}
@@ -156,6 +162,9 @@ func resourceTFEOAuthClientCreate(d *schema.ResourceData, meta interface{}) erro
156162
if serviceProvider == tfe.ServiceProviderBitbucket {
157163
options.Secret = tfe.String(secret)
158164
}
165+
if v, ok := d.GetOk("agent_pool_id"); ok && v.(string) != "" {
166+
options.AgentPool = &tfe.AgentPool{ID: *tfe.String(v.(string))}
167+
}
159168

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

internal/provider/resource_tfe_oauth_client_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,35 @@ func TestAccTFEOAuthClient_rsaKeys(t *testing.T) {
7575
})
7676
}
7777

78+
func TestAccTFEOAuthClient_agentPool(t *testing.T) {
79+
oc := &tfe.OAuthClient{}
80+
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
81+
82+
resource.Test(t, resource.TestCase{
83+
PreCheck: func() {
84+
testAccPreCheck(t)
85+
if envGithubToken == "" {
86+
t.Skip("Please set GITHUB_TOKEN to run this test")
87+
}
88+
},
89+
Providers: testAccProviders,
90+
CheckDestroy: testAccCheckTFEOAuthClientDestroy,
91+
Steps: []resource.TestStep{
92+
{
93+
Config: testAccTFEOAuthClient_agentPool(rInt),
94+
Check: resource.ComposeTestCheckFunc(
95+
testAccCheckTFEOAuthClientExists("tfe_oauth_client.foobar", oc),
96+
testAccCheckTFEOAuthClientAttributes(oc),
97+
resource.TestCheckResourceAttr(
98+
"tfe_oauth_client.foobar", "service_provider", "github_enterprise"),
99+
resource.TestCheckResourceAttr(
100+
"tfe_workspace.foobar", "agent_pool_id", ""),
101+
),
102+
},
103+
},
104+
})
105+
}
106+
78107
func testAccCheckTFEOAuthClientExists(
79108
n string, oc *tfe.OAuthClient) resource.TestCheckFunc {
80109
return func(s *terraform.State) error {
@@ -183,3 +212,25 @@ hwIDAQAB
183212
EOT
184213
}`, rInt)
185214
}
215+
216+
func testAccTFEOAuthClient_agentPool(rInt int) string {
217+
return fmt.Sprintf(`
218+
resource "tfe_organization" "foobar" {
219+
name = "tst-terraform-%d"
220+
221+
}
222+
223+
resource "tfe_agent_pool" "foobar" {
224+
name = "agent-pool-test"
225+
organization = tfe_organization.foobar.name
226+
}
227+
228+
resource "tfe_oauth_client" "foobar" {
229+
organization = tfe_organization.foobar.id
230+
api_url = "https://githubenterprise.xxx"
231+
http_url = "https://githubenterprise.xxx"
232+
oauth_token = "%s"
233+
service_provider = "github_enterprise"
234+
agent_pool_id = tfe_agent_pool.foobar.id
235+
}`, rInt, envGithubToken)
236+
}

0 commit comments

Comments
 (0)