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

Adding resource github_organization_settings to provider closes#1125 #1298

Merged
merged 2 commits into from Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions github/provider.go
Expand Up @@ -109,6 +109,7 @@ func Provider() terraform.ResourceProvider {
"github_membership": resourceGithubMembership(),
"github_organization_block": resourceOrganizationBlock(),
"github_organization_project": resourceGithubOrganizationProject(),
"github_organization_settings": resouceGithubOrganizationSettings(),
"github_organization_webhook": resourceGithubOrganizationWebhook(),
"github_project_card": resourceGithubProjectCard(),
"github_project_column": resourceGithubProjectColumn(),
Expand Down
370 changes: 370 additions & 0 deletions github/resource_github_organization_settings.go

Large diffs are not rendered by default.

183 changes: 183 additions & 0 deletions github/resource_github_organization_settings_test.go
@@ -0,0 +1,183 @@
package github

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccGithubOrganizationSettings(t *testing.T) {
t.Run("creates organization settings without error", func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are passing for me locally!


config := `
resource "github_organization_settings" "test" {
billing_email = "test@example.com"
company = "Test Company"
blog = "https://example.com"
email = "test@example.com"
twitter_username = "Test"
location = "Test Location"
name = "Test Name"
description = "Test Description"
has_organization_projects = true
has_repository_projects = true
default_repository_permission = "read"
members_can_create_repositories = true
members_can_create_public_repositories = true
members_can_create_private_repositories = true
members_can_create_internal_repositories = false
members_can_create_pages = true
members_can_create_public_pages = true
members_can_create_private_pages = true
members_can_fork_private_repositories = true
web_commit_signoff_required = true
advanced_security_enabled_for_new_repositories = false
dependabot_alerts_enabled_for_new_repositories= false
dependabot_security_updates_enabled_for_new_repositories = false
dependency_graph_enabled_for_new_repositories = false
secret_scanning_enabled_for_new_repositories = false
secret_scanning_push_protection_enabled_for_new_repositories = false
}`

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_organization_settings.test",
"billing_email", "test@example.com",
),
)
testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
},
})
}
t.Run("run with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})
t.Run("run with an individual account", func(t *testing.T) {
t.Skip("individual account not supported for this operation")
})
t.Run("run with an organization account", func(t *testing.T) {
testCase(t, organization)
})

})
t.Run("updates organization settings without error", func(t *testing.T) {
billingEmail := "test1@example.com"
company := "Test Company"
blog := "https://test.com"
updatedBillingEmail := "test2@example.com"
updatedCompany := "Test Company 2"
updatedBlog := "https://test2.com"

configs := map[string]string{
"before": fmt.Sprintf(`
resource "github_organization_settings" "test" {
billing_email = "%s"
company = "%s"
blog = "%s"
}`, billingEmail, company, blog),

"after": fmt.Sprintf(`
resource "github_organization_settings" "test" {
billing_email = "%s"
company = "%s"
blog = "%s"
}`, updatedBillingEmail, updatedCompany, updatedBlog),
}
checks := map[string]resource.TestCheckFunc{
"before": resource.TestCheckResourceAttr(
"github_organization_settings.test",
"billing_email", billingEmail,
),
"after": resource.TestCheckResourceAttr(
"github_organization_settings.test",
"billing_email", updatedBillingEmail,
),
}
testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: configs["before"],
Check: checks["before"],
},
{
Config: configs["after"],
Check: checks["after"],
},
},
})
}

t.Run("with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})

t.Run("with an individual account", func(t *testing.T) {
t.Skip("individual account not supported for this operation")
})

t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})
})

t.Run("imports organization settings without error", func(t *testing.T) {
billingEmail := "test@example.com"
company := "Test Company"
blog := "https://example.com"

config := fmt.Sprintf(`
resource "github_organization_settings" "test" {
billing_email = "%s"
company = "%s"
blog = "%s"
}`, billingEmail, company, blog)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_organization_settings.test",
"billing_email", billingEmail,
),
)

testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
{
ResourceName: "github_organization_settings.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
t.Run("with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})

t.Run("with an individual account", func(t *testing.T) {
t.Skip("individual account not supported for this operation")
})

t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})
})
}
2 changes: 1 addition & 1 deletion github/resource_github_repository_tag_protection.go
Expand Up @@ -21,7 +21,7 @@ func resourceGithubRepositoryTagProtection() *schema.Resource {
State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
parts := strings.Split(d.Id(), "/")
if len(parts) != 2 {
return nil, fmt.Errorf("Invalid ID specified. Supplied ID must be written as <repository>/<webhook_id>")
return nil, fmt.Errorf("Invalid ID specified. Supplied ID must be written as <repository>/<tag_protection_id>")
}
d.Set("repository", parts[0])
d.Set("tag_protection_id", parts[1])
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -18,7 +18,7 @@ require (
github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0 // indirect
github.com/golangci/misspell v0.3.5 // indirect
github.com/golangci/revgrep v0.0.0-20220804021717-745bb2f7c2e6 // indirect
github.com/google/go-github/v47 v47.0.0
github.com/google/go-github/v47 v47.1.0
github.com/google/uuid v1.3.0 // indirect
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
github.com/gostaticanalysis/testutil v0.4.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Expand Up @@ -315,8 +315,12 @@ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v47 v47.0.0 h1:eQap5bIRZibukP0VhngWgpuM0zhY4xntqOzn6DhdkE4=
github.com/google/go-github/v47 v47.0.0/go.mod h1:DRjdvizXE876j0YOZwInB1ESpOcU/xFBClNiQLSdorE=
github.com/google/go-github/v47 v47.1.0 h1:Cacm/WxQBOa9lF0FT0EMjZ2BWMetQ1TQfyurn4yF1z8=
github.com/google/go-github/v47 v47.1.0/go.mod h1:VPZBXNbFSJGjyjFRUKo9vZGawTajnWzC/YjGw/oFKi0=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
Expand Down
64 changes: 33 additions & 31 deletions vendor/github.com/google/go-cmp/cmp/compare.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 24 additions & 20 deletions vendor/github.com/google/go-cmp/cmp/internal/diff/diff.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.