Skip to content

Commit 379dafc

Browse files
authored
feat: add terrakube_vcs resource (#59)
Additional changes: 1. Rename file name `organization_template_data_resource.go` to `organization_template_data_source.go` to be consistent with other file names 2. Add more attribute reference to `terrakube_vcs` data source
1 parent a3d2c7b commit 379dafc

File tree

10 files changed

+571
-3
lines changed

10 files changed

+571
-3
lines changed

docs/resources/vcs.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "terrakube_vcs Resource - terraform-provider-terrakube"
4+
subcategory: ""
5+
description: |-
6+
7+
---
8+
9+
# terrakube_vcs (Resource)
10+
11+
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `client_id` (String) The client ID of the VCS connection
21+
- `client_secret` (String, Sensitive) The secret of the VCS connection
22+
- `name` (String) The name of the VCS connection
23+
- `organization_id` (String) Terrakube organization id
24+
25+
### Optional
26+
27+
- `api_url` (String) The API URL of the VCS connection
28+
- `description` (String) The description of the VCS connection
29+
- `endpoint` (String) The endpoint of the VCS connection
30+
- `vcs_type` (String) Variable description
31+
32+
### Read-Only
33+
34+
- `connect_url` (String) The connect URL of the VCS connection, after adding the VCS connection, please logon to this URL to connect.
35+
- `id` (String) Variable Id
36+
- `status` (String) The status of the VCS connection. IMPORTANT NOTE: if the status is not 'PENDING', please logon to the connect_url to connect!!.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resource "terrakube_vcs" "vcs" {
2+
organization_id = data.terrakube_organization.org.id
3+
name = "Github"
4+
description = "test github connection"
5+
vcs_type = "GITHUB"
6+
client_id = "Iv1.1b9b7b1b1b1b1b1b"
7+
client_secret = "hellotest"
8+
endpoint = "https://github.com"
9+
api_url = "https://api.github.com"
10+
}

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/google/jsonapi v1.0.0
88
github.com/hashicorp/terraform-plugin-docs v0.18.0
99
github.com/hashicorp/terraform-plugin-framework v1.10.0
10+
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0
1011
github.com/hashicorp/terraform-plugin-log v0.9.0
1112
)
1213

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ github.com/hashicorp/terraform-plugin-docs v0.18.0 h1:2bINhzXc+yDeAcafurshCrIjtd
7676
github.com/hashicorp/terraform-plugin-docs v0.18.0/go.mod h1:iIUfaJpdUmpi+rI42Kgq+63jAjI8aZVTyxp3Bvk9Hg8=
7777
github.com/hashicorp/terraform-plugin-framework v1.10.0 h1:xXhICE2Fns1RYZxEQebwkB2+kXouLC932Li9qelozrc=
7878
github.com/hashicorp/terraform-plugin-framework v1.10.0/go.mod h1:qBXLDn69kM97NNVi/MQ9qgd1uWWsVftGSnygYG1tImM=
79+
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0 h1:bxZfGo9DIUoLLtHMElsu+zwqI4IsMZQBRRy4iLzZJ8E=
80+
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0/go.mod h1:wGeI02gEhj9nPANU62F2jCaHjXulejm/X+af4PdZaNo=
7981
github.com/hashicorp/terraform-plugin-go v0.23.0 h1:AALVuU1gD1kPb48aPQUjug9Ir/125t+AAurhqphJ2Co=
8082
github.com/hashicorp/terraform-plugin-go v0.23.0/go.mod h1:1E3Cr9h2vMlahWMbsSEcNrOCxovCZhOOIXjFHbjc/lQ=
8183
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=

internal/client/client.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,15 @@ type OrganizationVariableEntity struct {
8686
}
8787

8888
type VcsEntity struct {
89-
ID string `jsonapi:"primary,vcs"`
90-
Name string `jsonapi:"attr,name"`
91-
Description string `jsonapi:"attr,description"`
89+
ID string `jsonapi:"primary,vcs"`
90+
Name string `jsonapi:"attr,name"`
91+
Description string `jsonapi:"attr,description"`
92+
VcsType string `jsonapi:"attr,vcsType"`
93+
ClientId string `jsonapi:"attr,clientId"`
94+
ClientSecret string `jsonapi:"attr,clientSecret"`
95+
Endpoint string `jsonapi:"attr,endpoint"`
96+
ApiUrl string `jsonapi:"attr,apiUrl"`
97+
Status string `jsonapi:"attr,status"`
9298
}
9399

94100
type SshEntity struct {

internal/helpers/doc_site.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package helpers
2+
3+
func GetVCSProviderDoc() string {
4+
return "https://docs.terrakube.io/user-guide/vcs-providers"
5+
}

internal/provider/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func (p *TerrakubeProvider) Resources(ctx context.Context) []func() resource.Res
180180
NewWorkspaceTagResource,
181181
NewWorkspaceVariableResource,
182182
NewWorkspaceVcsResource,
183+
NewVcsResource,
183184
}
184185
}
185186

internal/provider/vcs_data_source.go

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ type VcsDataSourceModel struct {
2828
OrganizationId types.String `tfsdk:"organization_id"`
2929
Name types.String `tfsdk:"name"`
3030
Description types.String `tfsdk:"description"`
31+
ClientId types.String `tfsdk:"client_id"`
32+
Endpoint types.String `tfsdk:"endpoint"`
33+
ApiUrl types.String `tfsdk:"api_url"`
34+
Status types.String `tfsdk:"status"`
3135
}
3236

3337
type VcsDataSource struct {
@@ -140,6 +144,10 @@ func (d *VcsDataSource) Read(ctx context.Context, req datasource.ReadRequest, re
140144
data, _ := vcs.(*client.VcsEntity)
141145
state.ID = types.StringValue(data.ID)
142146
state.Description = types.StringValue(data.Description)
147+
state.ClientId = types.StringValue(data.ClientId)
148+
state.Endpoint = types.StringValue(data.Endpoint)
149+
state.ApiUrl = types.StringValue(data.ApiUrl)
150+
state.Status = types.StringValue(data.Status)
143151
}
144152

145153
diags := resp.State.Set(ctx, &state)

0 commit comments

Comments
 (0)