Skip to content

Commit 0ff1630

Browse files
authored
Add support for configuring version control system (#19)
* Update to use the new library (https://github.com/tomtucka/go-circleci) * Add support for configuring the version control system * Update documentation
1 parent 816c395 commit 0ff1630

10 files changed

+42
-12
lines changed

circleci/config.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package circleci
22

33
import (
4-
"github.com/jszwedko/go-circleci"
4+
"github.com/TomTucka/go-circleci"
55
)
66

77
type Config struct {
88
Token string
99
Organization string
10+
vcs string
1011
}
1112

1213
type Organization struct {
1314
name string
15+
VCS string
1416
client *circleci.Client
1517
}
1618

@@ -19,6 +21,7 @@ func (c *Config) Client() (interface{}, error) {
1921

2022
org.name = c.Organization
2123
org.client = &circleci.Client{Token: c.Token}
24+
org.VCS = c.vcs
2225

2326
return &org, nil
2427
}

circleci/provider.go

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ func Provider() *schema.Provider {
1919
DefaultFunc: schema.EnvDefaultFunc("CIRCLECI_ORGANIZATION", nil),
2020
Description: "CircleCI organization name to manage.",
2121
},
22+
"vcs_type": {
23+
Type: schema.TypeString,
24+
Required: true,
25+
DefaultFunc: schema.EnvDefaultFunc("CIRCLECI_VCS_TYPE", "github"),
26+
Description: "The VCS type for the organization.",
27+
},
2228
},
2329
ResourcesMap: map[string]*schema.Resource{
2430
"circleci_project": resourceCircleciProject(),
@@ -34,6 +40,7 @@ func providerConfiguretest(p *schema.Provider) schema.ConfigureFunc {
3440
config := Config{
3541
Token: d.Get("token").(string),
3642
Organization: d.Get("organization").(string),
43+
vcs: d.Get("vcs_type").(string),
3744
}
3845

3946
return config.Client()

circleci/provider_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package circleci
22

33
import (
4-
"github.com/stretchr/testify/require"
54
"testing"
5+
6+
"github.com/stretchr/testify/require"
67
)
78

89
func TestProvider_HasChildResources(t *testing.T) {
@@ -24,11 +25,13 @@ func TestProvider_SchemaIsValid(t *testing.T) {
2425
type testParams struct {
2526
token string
2627
organization string
28+
vcs string
2729
}
2830

2931
tests := []testParams{
30-
{"myTestToken", "terraform-providers-circleci"},
31-
{"myTestToken", "terraform-providers-circleci"},
32+
{"myTestToken", "terraform-providers-circleci", "github"},
33+
{"myTestToken", "terraform-providers-circleci", "github"},
34+
{"myTestToken", "terraform-providers-circleci", "github"},
3235
}
3336

3437
schema := Provider().Schema
@@ -37,5 +40,6 @@ func TestProvider_SchemaIsValid(t *testing.T) {
3740
for _, test := range tests {
3841
require.NotEmpty(t, test.token, "A property in the schema cannot have a nil value")
3942
require.NotNil(t, test.organization, "A property in the schema cannot have a nil value")
43+
require.NotNil(t, test.organization, "A property in the schema cannot have a nil value")
4044
}
4145
}

circleci/resource_circleci_environment_variable.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package circleci
22

33
import (
44
"fmt"
5+
56
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
67
)
78

@@ -35,10 +36,11 @@ func resourceCircleciEnvVar() *schema.Resource {
3536
func resourceCircleciEnvVarCreate(d *schema.ResourceData, meta interface{}) error {
3637
client := meta.(*Organization).client
3738
organization := meta.(*Organization).name
39+
vcs := meta.(*Organization).VCS
3840
project := d.Get("project").(string)
3941
name := d.Get("name").(string)
4042
value := d.Get("value").(string)
41-
_, err := client.AddEnvVar(organization, project, name, value)
43+
_, err := client.AddEnvVar(vcs, organization, project, name, value)
4244
if err != nil {
4345
return err
4446
}
@@ -57,7 +59,8 @@ func resourceCircleciEnvVarUpdate(d *schema.ResourceData, meta interface{}) erro
5759
func resourceCircleciEnvVarDelete(d *schema.ResourceData, meta interface{}) error {
5860
client := meta.(*Organization).client
5961
organization := meta.(*Organization).name
62+
vcs := meta.(*Organization).VCS
6063
project := d.Get("project").(string)
6164
name := d.Get("name").(string)
62-
return client.DeleteEnvVar(organization, project, name)
65+
return client.DeleteEnvVar(vcs, organization, project, name)
6366
}

circleci/resource_circleci_project.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,19 @@ func resourceCircleciProject() *schema.Resource {
3131
func resourceCircleciProjectCreate(d *schema.ResourceData, m interface{}) error {
3232
client := m.(*Organization).client
3333
organization := m.(*Organization).name
34+
vcs := m.(*Organization).VCS
3435
project := d.Get("name").(string)
3536
envVars := d.Get("env_vars").(map[string]interface{})
3637

37-
_, err := client.FollowProject(organization, project)
38+
_, err := client.FollowProject(vcs, organization, project)
3839
if err != nil {
3940
return err
4041
}
4142

4243
d.SetId(project)
4344

4445
for name, value := range envVars {
45-
_, err := client.AddEnvVar(organization, project, name, value.(string))
46+
_, err := client.AddEnvVar(vcs, organization, project, name, value.(string))
4647
if err != nil {
4748
return err
4849
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ go 1.14
44

55
require (
66
github.com/hashicorp/terraform-plugin-sdk/v2 v2.0.0-rc.2
7-
github.com/jszwedko/go-circleci v0.3.0
7+
github.com/TomTucka/go-circleci v0.4.0
88
github.com/stretchr/testify v1.3.0
99
)

go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbf
99
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
1010
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
1111
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
12+
github.com/TomTucka/go-circleci v0.4.0 h1:bdpyE9CeIwuCHdy+XhF4zccchf5lkkBsZnaRHszEvKw=
13+
github.com/TomTucka/go-circleci v0.4.0/go.mod h1:PHouc3cpjYcabxbkLi/XG3EEu/pAWaBWdyJGlXn3aqY=
14+
github.com/TomTucka/go-circleci v1.0.0 h1:T6cXnkJ4FVpk9eSZNMxYWQwFLBlKs5nkaeCqrg+Vaow=
1215
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
1316
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
1417
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=

website/docs/index.html.markdown

+12-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@ The CircleCI provider provides resources to interact with and manage CircleCI pr
1313

1414
```terraform
1515
provider "circleci" {
16-
token = var.circleci_token
17-
organization = "YourOrganizationName"
16+
token = var.circleci_token # optionally use CIRCLECI_TOKEN env var
17+
organization = "YourOrganizationName" # optionally use CIRCLECI_ORGANIZATION env var
18+
vcs_type = "github" # optionally use CIRCLECI_VCS_TYPE env var
1819
}
19-
```
20+
```
21+
22+
## Schema
23+
24+
- **token** (String, Required) CircleCI API Token. You can create this in your account dashboard. Can be specified with the CIRCLECI_TOKEN environment variable.
25+
26+
- **organization** (String, Required) Configure what organization you are using in CircleCI. Can be specified with the CIRCLECI_ORGANIZATION environment variable.
27+
28+
- **vcs_type** (String, Required) Configure what version control system type your project uses. You may currently select either ‘github’ or ‘bitbucket’. Can be specified with the CIRCLECI_VCS_TYPE environment variable.
File renamed without changes.

0 commit comments

Comments
 (0)