Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initialize_with_readme to project #179

Merged
merged 2 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions gitlab/resource_gitlab_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ var resourceGitLabProjectSchema = map[string]*schema.Schema{
return true
}

// Once the initialize_with_readme attribute is set to true, Gitlab creates
// a master branch and sets it as default. If the Gitlab project resource
// doesn't have default_branch attribute specified, Terraform will
// force "master" => "" on the next run.
if v, ok := d.GetOk("initialize_with_readme"); ok {
if new == "" && v == true {
return true
}
}

return old == new
},
},
Expand Down Expand Up @@ -161,6 +171,10 @@ var resourceGitLabProjectSchema = map[string]*schema.Schema{
Optional: true,
Default: false,
},
"initialize_with_readme": {
Type: schema.TypeBool,
Optional: true,
},
}

func resourceGitlabProject() *schema.Resource {
Expand Down Expand Up @@ -260,6 +274,11 @@ func resourceGitlabProjectCreate(d *schema.ResourceData, meta interface{}) error
setProperties = append(setProperties, "tags")
}

if v, ok := d.GetOk("initialize_with_readme"); ok {
options.InitializeWithReadme = gitlab.Bool(v.(bool))
setProperties = append(setProperties, "initialize_with_readme")
}

log.Printf("[DEBUG] create gitlab project %q", *options.Name)

project, _, err := client.Projects.CreateProject(options)
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/project.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ The following arguments are supported:

* `archived` - (Optional) Whether the project is in read-only mode (archived). Repositories can be archived/unarchived by toggling this parameter.

* `initialize_with_readme` - (Optional) Create master branch with first commit containing a README.md file.

## Attributes Reference

The following additional attributes are exported:
Expand Down