provider/gitlab: Addition of the documentation link for gitlab to sidebar

```
% make testacc TEST=./builtin/providers/gitlab
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/04/27 05:37:02 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/gitlab -v  -timeout 120m
=== RUN   TestProvider
--- PASS: TestProvider (0.00s)
=== RUN   TestProvider_impl
--- PASS: TestProvider_impl (0.00s)
=== RUN   TestAccGitlabProject_basic
--- PASS: TestAccGitlabProject_basic (41.11s)
=== RUN   TestGitlab_validation
--- PASS: TestGitlab_validation (0.00s)
=== RUN   TestGitlab_visbilityHelpers
--- PASS: TestGitlab_visbilityHelpers (0.00s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/gitlab	41.125s
```
This commit is contained in:
stack72 2017-04-27 05:44:05 +12:00
parent 898ac02854
commit fd48f91876
No known key found for this signature in database
GPG Key ID: 8619A619B085CB16
7 changed files with 80 additions and 59 deletions

View File

@ -11,13 +11,13 @@ func Provider() terraform.ResourceProvider {
// The actual provider // The actual provider
return &schema.Provider{ return &schema.Provider{
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"token": &schema.Schema{ "token": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
DefaultFunc: schema.EnvDefaultFunc("GITLAB_TOKEN", nil), DefaultFunc: schema.EnvDefaultFunc("GITLAB_TOKEN", nil),
Description: descriptions["token"], Description: descriptions["token"],
}, },
"base_url": &schema.Schema{ "base_url": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
DefaultFunc: schema.EnvDefaultFunc("GITLAB_BASE_URL", ""), DefaultFunc: schema.EnvDefaultFunc("GITLAB_BASE_URL", ""),

View File

@ -5,6 +5,7 @@ import (
"log" "log"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
gitlab "github.com/xanzy/go-gitlab" gitlab "github.com/xanzy/go-gitlab"
) )
@ -16,54 +17,54 @@ func resourceGitlabProject() *schema.Resource {
Delete: resourceGitlabProjectDelete, Delete: resourceGitlabProjectDelete,
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"name": &schema.Schema{ "name": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
}, },
"description": &schema.Schema{ "description": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
}, },
"default_branch": &schema.Schema{ "default_branch": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
}, },
"issues_enabled": &schema.Schema{ "issues_enabled": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
Default: true, Default: true,
}, },
"merge_requests_enabled": &schema.Schema{ "merge_requests_enabled": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
Default: true, Default: true,
}, },
"wiki_enabled": &schema.Schema{ "wiki_enabled": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
Default: true, Default: true,
}, },
"snippets_enabled": &schema.Schema{ "snippets_enabled": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
Default: true, Default: true,
}, },
"visibility_level": &schema.Schema{ "visibility_level": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ValidateFunc: validateValueFunc([]string{"private", "internal", "public"}), ValidateFunc: validation.StringInSlice([]string{"private", "internal", "public"}, true),
Default: "private", Default: "private",
}, },
"ssh_url_to_repo": &schema.Schema{ "ssh_url_to_repo": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"http_url_to_repo": &schema.Schema{ "http_url_to_repo": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"web_url": &schema.Schema{ "web_url": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
@ -71,7 +72,7 @@ func resourceGitlabProject() *schema.Resource {
} }
} }
func resourceGitlabProjectUpdateFromAPI(d *schema.ResourceData, project *gitlab.Project) { func resourceGitlabProjectSetToState(d *schema.ResourceData, project *gitlab.Project) {
d.Set("name", project.Name) d.Set("name", project.Name)
d.Set("description", project.Description) d.Set("description", project.Description)
d.Set("default_branch", project.DefaultBranch) d.Set("default_branch", project.DefaultBranch)
@ -89,29 +90,17 @@ func resourceGitlabProjectUpdateFromAPI(d *schema.ResourceData, project *gitlab.
func resourceGitlabProjectCreate(d *schema.ResourceData, meta interface{}) error { func resourceGitlabProjectCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*gitlab.Client) client := meta.(*gitlab.Client)
options := &gitlab.CreateProjectOptions{ options := &gitlab.CreateProjectOptions{
Name: gitlab.String(d.Get("name").(string)), Name: gitlab.String(d.Get("name").(string)),
IssuesEnabled: gitlab.Bool(d.Get("issues_enabled").(bool)),
MergeRequestsEnabled: gitlab.Bool(d.Get("merge_requests_enabled").(bool)),
WikiEnabled: gitlab.Bool(d.Get("wiki_enabled").(bool)),
SnippetsEnabled: gitlab.Bool(d.Get("snippets_enabled").(bool)),
} }
if v, ok := d.GetOk("description"); ok { if v, ok := d.GetOk("description"); ok {
options.Description = gitlab.String(v.(string)) options.Description = gitlab.String(v.(string))
} }
if v, ok := d.GetOk("issues_enabled"); ok {
options.IssuesEnabled = gitlab.Bool(v.(bool))
}
if v, ok := d.GetOk("merge_requests_enabled"); ok {
options.MergeRequestsEnabled = gitlab.Bool(v.(bool))
}
if v, ok := d.GetOk("wiki_enabled"); ok {
options.WikiEnabled = gitlab.Bool(v.(bool))
}
if v, ok := d.GetOk("snippets_enabled"); ok {
options.SnippetsEnabled = gitlab.Bool(v.(bool))
}
if v, ok := d.GetOk("visibility_level"); ok { if v, ok := d.GetOk("visibility_level"); ok {
options.VisibilityLevel = stringToVisibilityLevel(v.(string)) options.VisibilityLevel = stringToVisibilityLevel(v.(string))
} }
@ -125,9 +114,7 @@ func resourceGitlabProjectCreate(d *schema.ResourceData, meta interface{}) error
d.SetId(fmt.Sprintf("%d", project.ID)) d.SetId(fmt.Sprintf("%d", project.ID))
resourceGitlabProjectUpdateFromAPI(d, project) return resourceGitlabProjectRead(d, meta)
return nil
} }
func resourceGitlabProjectRead(d *schema.ResourceData, meta interface{}) error { func resourceGitlabProjectRead(d *schema.ResourceData, meta interface{}) error {
@ -145,7 +132,7 @@ func resourceGitlabProjectRead(d *schema.ResourceData, meta interface{}) error {
return err return err
} }
resourceGitlabProjectUpdateFromAPI(d, project) resourceGitlabProjectSetToState(d, project)
return nil return nil
} }
@ -188,19 +175,17 @@ func resourceGitlabProjectUpdate(d *schema.ResourceData, meta interface{}) error
log.Printf("[DEBUG] update gitlab project %s", d.Id()) log.Printf("[DEBUG] update gitlab project %s", d.Id())
project, _, err := client.Projects.EditProject(d.Id(), options) _, _, err := client.Projects.EditProject(d.Id(), options)
if err != nil { if err != nil {
return err return err
} }
resourceGitlabProjectUpdateFromAPI(d, project) return resourceGitlabProjectRead(d, meta)
return nil
} }
func resourceGitlabProjectDelete(d *schema.ResourceData, meta interface{}) error { func resourceGitlabProjectDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*gitlab.Client) client := meta.(*gitlab.Client)
log.Printf("[DEBUG] update gitlab project %s", d.Id()) log.Printf("[DEBUG] Delete gitlab project %s", d.Id())
_, err := client.Projects.DeleteProject(d.Id()) _, err := client.Projects.DeleteProject(d.Id())
return err return err

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
"github.com/xanzy/go-gitlab" "github.com/xanzy/go-gitlab"
@ -11,6 +12,7 @@ import (
func TestAccGitlabProject_basic(t *testing.T) { func TestAccGitlabProject_basic(t *testing.T) {
var project gitlab.Project var project gitlab.Project
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -18,12 +20,12 @@ func TestAccGitlabProject_basic(t *testing.T) {
CheckDestroy: testAccCheckGitlabProjectDestroy, CheckDestroy: testAccCheckGitlabProjectDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
// Create a project with all the features on // Create a project with all the features on
resource.TestStep{ {
Config: testAccGitlabProjectConfig, Config: testAccGitlabProjectConfig(rInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckGitlabProjectExists("gitlab_project.foo", &project), testAccCheckGitlabProjectExists("gitlab_project.foo", &project),
testAccCheckGitlabProjectAttributes(&project, &testAccGitlabProjectExpectedAttributes{ testAccCheckGitlabProjectAttributes(&project, &testAccGitlabProjectExpectedAttributes{
Name: "foo", Name: fmt.Sprintf("foo-%d", rInt),
Description: "Terraform acceptance tests", Description: "Terraform acceptance tests",
IssuesEnabled: true, IssuesEnabled: true,
MergeRequestsEnabled: true, MergeRequestsEnabled: true,
@ -34,24 +36,24 @@ func TestAccGitlabProject_basic(t *testing.T) {
), ),
}, },
// Update the project to turn the features off // Update the project to turn the features off
resource.TestStep{ {
Config: testAccGitlabProjectUpdateConfig, Config: testAccGitlabProjectUpdateConfig(rInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckGitlabProjectExists("gitlab_project.foo", &project), testAccCheckGitlabProjectExists("gitlab_project.foo", &project),
testAccCheckGitlabProjectAttributes(&project, &testAccGitlabProjectExpectedAttributes{ testAccCheckGitlabProjectAttributes(&project, &testAccGitlabProjectExpectedAttributes{
Name: "foo", Name: fmt.Sprintf("foo-%d", rInt),
Description: "Terraform acceptance tests!", Description: "Terraform acceptance tests!",
VisibilityLevel: 20, VisibilityLevel: 20,
}), }),
), ),
}, },
// Update the project to turn the features on again //Update the project to turn the features on again
resource.TestStep{ {
Config: testAccGitlabProjectConfig, Config: testAccGitlabProjectConfig(rInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckGitlabProjectExists("gitlab_project.foo", &project), testAccCheckGitlabProjectExists("gitlab_project.foo", &project),
testAccCheckGitlabProjectAttributes(&project, &testAccGitlabProjectExpectedAttributes{ testAccCheckGitlabProjectAttributes(&project, &testAccGitlabProjectExpectedAttributes{
Name: "foo", Name: fmt.Sprintf("foo-%d", rInt),
Description: "Terraform acceptance tests", Description: "Terraform acceptance tests",
IssuesEnabled: true, IssuesEnabled: true,
MergeRequestsEnabled: true, MergeRequestsEnabled: true,
@ -157,20 +159,23 @@ func testAccCheckGitlabProjectDestroy(s *terraform.State) error {
return nil return nil
} }
const testAccGitlabProjectConfig = ` func testAccGitlabProjectConfig(rInt int) string {
return fmt.Sprintf(`
resource "gitlab_project" "foo" { resource "gitlab_project" "foo" {
name = "foo" name = "foo-%d"
description = "Terraform acceptance tests" description = "Terraform acceptance tests"
# So that acceptance tests can be run in a gitlab organization # So that acceptance tests can be run in a gitlab organization
# with no billing # with no billing
visibility_level = "public" visibility_level = "public"
} }
` `, rInt)
}
const testAccGitlabProjectUpdateConfig = ` func testAccGitlabProjectUpdateConfig(rInt int) string {
return fmt.Sprintf(`
resource "gitlab_project" "foo" { resource "gitlab_project" "foo" {
name = "foo" name = "foo-%d"
description = "Terraform acceptance tests!" description = "Terraform acceptance tests!"
# So that acceptance tests can be run in a gitlab organization # So that acceptance tests can be run in a gitlab organization
@ -182,4 +187,5 @@ resource "gitlab_project" "foo" {
wiki_enabled = false wiki_enabled = false
snippets_enabled = false snippets_enabled = false
} }
` `, rInt)
}

View File

@ -17,7 +17,7 @@ Use the navigation to the left to read about the available resources.
## Example Usage ## Example Usage
``` ```hcl
# Configure the GitLab Provider # Configure the GitLab Provider
provider "gitlab" { provider "gitlab" {
token = "${var.github_token}" token = "${var.github_token}"

View File

@ -14,7 +14,7 @@ GitLab organization.
## Example Usage ## Example Usage
``` ```hcl
resource "gitlab_repository" "example" { resource "gitlab_repository" "example" {
name = "example" name = "example"
description = "My awesome codebase" description = "My awesome codebase"

View File

@ -272,6 +272,10 @@
<a href="/docs/providers/github/index.html">GitHub</a> <a href="/docs/providers/github/index.html">GitHub</a>
</li> </li>
<li<%= sidebar_current("docs-providers-gitlab") %>>
<a href="/docs/providers/gitlab/index.html">Gitlab</a>
</li>
<li<%= sidebar_current("docs-providers-google") %>> <li<%= sidebar_current("docs-providers-google") %>>
<a href="/docs/providers/google/index.html">Google Cloud</a> <a href="/docs/providers/google/index.html">Google Cloud</a>
</li> </li>

View File

@ -0,0 +1,26 @@
<% wrap_layout :inner do %>
<% content_for :sidebar do %>
<div class="docs-sidebar hidden-print affix-top" role="complementary">
<ul class="nav docs-sidenav">
<li<%= sidebar_current("docs-home") %>>
<a href="/docs/providers/index.html">All Providers</a>
</li>
<li<%= sidebar_current("docs-gitlab-index") %>>
<a href="/docs/providers/gitlab/index.html">Gitlab Provider</a>
</li>
<li<%= sidebar_current("docs-gitlab-resource") %>>
<a href="#">Resources</a>
<ul class="nav nav-visible">
<li<%= sidebar_current("docs-gitlab-resource-project") %>>
<a href="/docs/providers/gitlab/r/project.html">gitlab_project</a>
</li>
</ul>
</li>
</ul>
</div>
<% end %>
<%= yield %>
<% end %>