Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export DG_API_KEY=""
export DG_USER_NAME=""
export TF_VAR_app_id=""
export TF_VAR_owner=""
export TF_VAR_platform=""
export TF_VAR_add_user_name=""
export TF_VAR_organization=""
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ crash.log
.terraform
*.tfstate
*.tfstate.*

# Go module
vendor
26 changes: 0 additions & 26 deletions deploygate/data_source_app_collaborator.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,6 @@ func dataSourceAppCollaborator() *schema.Resource {
},
},
},
"teams": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
},
"role": {
Type: schema.TypeInt,
Optional: true,
},
},
},
},
"usage": {
Type: schema.TypeMap,
Computed: true,
Elem: schema.TypeInt,
},
},
}
}
Expand Down Expand Up @@ -91,11 +70,6 @@ func dataSourceAppCollaboratorRead(d *schema.ResourceData, meta interface{}) err

d.SetId(fmt.Sprintf("%s/%s/%s", owner, platform, appID))
d.Set("users", rs.Users)
d.Set("teams", rs.Teams)
d.Set("usage", map[string]interface{}{
"max": rs.Usage.Max,
"used": rs.Usage.Used,
})

return nil
}
2 changes: 1 addition & 1 deletion deploygate/data_source_app_collaborator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func testDataSourceAppCollaborator(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Can't find app users resource: %s", n)
return fmt.Errorf("Can't find resource: %s", n)
}

if rs.Primary.ID == "" {
Expand Down
75 changes: 75 additions & 0 deletions deploygate/data_source_organization_member.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package deploygate

import (
"fmt"
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
go_deploygate "github.com/recruit-mp/go-deploygate"
)

func dataSourceOrganizationMember() *schema.Resource {
return &schema.Resource{
Read: dataSourceOrganizationMemberRead,

Schema: map[string]*schema.Schema{
"organization": {
Type: schema.TypeString,
Required: true,
},
"members": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Optional: true,
},
"name": {
Type: schema.TypeString,
Optional: true,
},
"url": {
Type: schema.TypeString,
Optional: true,
},
"icon_url": {
Type: schema.TypeString,
Optional: true,
},
"inviting": {
Type: schema.TypeBool,
Optional: true,
},
},
},
},
},
}
}

func dataSourceOrganizationMemberRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Client).client

organization := d.Get("organization").(string)

log.Printf("[DEBUG] dataSourceOrganizationMemberRead: %s", organization)

g := &go_deploygate.GetOrganizationMemberInput{
OrganizationName: organization,
}

om, err := client.GetOrganizationMember(g)

if err != nil {
return err
}

rs := om

d.SetId(fmt.Sprintf("%s", organization))
d.Set("members", rs.Members)

return nil
}
53 changes: 53 additions & 0 deletions deploygate/data_source_organization_member_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package deploygate

import (
"fmt"
"testing"

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

func Test_DataSourceOrganizationMember_basic(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { Test_DGPreCheck(t) },
Providers: testDGProviders,
Steps: []resource.TestStep{
{
Config: testDataSourceOrganizationMemberConfig,
Check: resource.ComposeTestCheckFunc(
testDataSourceOrganizationMember("data.deploygate_organization_member.current"),
),
},
},
})
}

func testDataSourceOrganizationMember(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Can't find resource: %s", n)
}

if rs.Primary.ID == "" {
return fmt.Errorf("Resource ID not set")
}

if rs.Primary.Attributes["organization"] == "" {
return fmt.Errorf("organization expected to not be nil")
}

return nil
}
}

const testDataSourceOrganizationMemberConfig = `
data "deploygate_organization_member" "current" {
organization = var.organization
}
variable "organization" {
type = string
}
`
14 changes: 2 additions & 12 deletions deploygate/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,10 @@ func Provider() *schema.Provider {
Sensitive: true,
DefaultFunc: schema.EnvDefaultFunc("DG_API_KEY", nil),
},
"user_name": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("DG_USER_NAME", nil),
},
"organization_name": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
DefaultFunc: schema.EnvDefaultFunc("DG_ORGANIZATION_NAME", nil),
},
},
DataSourcesMap: map[string]*schema.Resource{
"deploygate_app_collaborator": dataSourceAppCollaborator(),
"deploygate_app_collaborator": dataSourceAppCollaborator(),
"deploygate_organization_member": dataSourceOrganizationMember(),
},
ResourcesMap: map[string]*schema.Resource{
"deploygate_app_collaborator": resourceAppCollaborator(),
Expand Down
4 changes: 0 additions & 4 deletions deploygate/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ func Test_DGPreCheck(t *testing.T) {
t.Fatal("DG_API_KEY must be set for acceptance tests")
}

if os.Getenv("DG_USER_NAME") == "" && os.Getenv("DG_ORGANIZATION_NAME") == "" {
t.Fatal("DG_USER_NAME or DG_ORGANIZATION_NAME must be set for acceptance tests")
}

err := testDGProvider.Configure(context.Background(), terraform.NewResourceConfigRaw(nil))
if err != nil {
t.Fatal(err)
Expand Down
Loading