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
return &schema.Provider{
Schema: map[string]*schema.Schema{
"token": &schema.Schema{
"token": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("GITLAB_TOKEN", nil),
Description: descriptions["token"],
},
"base_url": &schema.Schema{
"base_url": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("GITLAB_BASE_URL", ""),

View File

@ -5,6 +5,7 @@ import (
"log"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
gitlab "github.com/xanzy/go-gitlab"
)
@ -16,54 +17,54 @@ func resourceGitlabProject() *schema.Resource {
Delete: resourceGitlabProjectDelete,
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"description": &schema.Schema{
"description": {
Type: schema.TypeString,
Optional: true,
},
"default_branch": &schema.Schema{
"default_branch": {
Type: schema.TypeString,
Optional: true,
},
"issues_enabled": &schema.Schema{
"issues_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"merge_requests_enabled": &schema.Schema{
"merge_requests_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"wiki_enabled": &schema.Schema{
"wiki_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"snippets_enabled": &schema.Schema{
"snippets_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"visibility_level": &schema.Schema{
"visibility_level": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateValueFunc([]string{"private", "internal", "public"}),
ValidateFunc: validation.StringInSlice([]string{"private", "internal", "public"}, true),
Default: "private",
},
"ssh_url_to_repo": &schema.Schema{
"ssh_url_to_repo": {
Type: schema.TypeString,
Computed: true,
},
"http_url_to_repo": &schema.Schema{
"http_url_to_repo": {
Type: schema.TypeString,
Computed: true,
},
"web_url": &schema.Schema{
"web_url": {
Type: schema.TypeString,
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("description", project.Description)
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 {
client := meta.(*gitlab.Client)
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 {
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 {
options.VisibilityLevel = stringToVisibilityLevel(v.(string))
}
@ -125,9 +114,7 @@ func resourceGitlabProjectCreate(d *schema.ResourceData, meta interface{}) error
d.SetId(fmt.Sprintf("%d", project.ID))
resourceGitlabProjectUpdateFromAPI(d, project)
return nil
return resourceGitlabProjectRead(d, meta)
}
func resourceGitlabProjectRead(d *schema.ResourceData, meta interface{}) error {
@ -145,7 +132,7 @@ func resourceGitlabProjectRead(d *schema.ResourceData, meta interface{}) error {
return err
}
resourceGitlabProjectUpdateFromAPI(d, project)
resourceGitlabProjectSetToState(d, project)
return nil
}
@ -188,19 +175,17 @@ func resourceGitlabProjectUpdate(d *schema.ResourceData, meta interface{}) error
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 {
return err
}
resourceGitlabProjectUpdateFromAPI(d, project)
return nil
return resourceGitlabProjectRead(d, meta)
}
func resourceGitlabProjectDelete(d *schema.ResourceData, meta interface{}) error {
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())
return err

View File

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

View File

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

View File

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