Skip to content

Commit 3b398d9

Browse files
authored
Merge pull request #27 from fnaoto/2022-11-23
2022 11 23
2 parents 333818c + f07c5ca commit 3b398d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1708
-746
lines changed

.env.sample

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
# Tokens
1+
# For organization
22

3-
export TF_VAR_user_api_key=""
3+
exoprt TF_VAR_team=""
4+
export TF_VAR_organization=""
45
export TF_VAR_organization_api_key=""
5-
export TF_VAR_enterprise_api_key=""
66

7-
# For app_member
7+
# For enterprise
88

9-
export TF_VAR_app_id=""
10-
export TF_VAR_owner=""
11-
export TF_VAR_platform=""
12-
export TF_VAR_add_user_name=""
9+
export TF_VAR_enterprise=""
10+
export TF_VAR_enterprise_api_key=""
1311

14-
# For organization_member
12+
# For member
1513

16-
export TF_VAR_organization=""
1714
export TF_VAR_add_member_name=""
18-
19-
# For organization_member
20-
21-
export TF_VAR_enterprise=""

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
[![release](https://github.com/fnaoto/terraform-provider-deploygate/actions/workflows/release.yml/badge.svg)](https://github.com/fnaoto/terraform-provider-deploygate/actions/workflows/release.yml)
44

55
- Documentation: [docs](docs)
6+
- Examples: [examples](examples)
67
- Website: [registry.terraform.io](https://registry.terraform.io/providers/fnaoto/deploygate/latest)
78

deploygate/data_source_app_member.go

Lines changed: 0 additions & 74 deletions
This file was deleted.

deploygate/data_source_app_member_test.go

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package deploygate
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
go_deploygate "github.com/fnaoto/go_deploygate"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
)
10+
11+
func dataSourceOrganizationTeamMember() *schema.Resource {
12+
return &schema.Resource{
13+
Read: dataSourceOrganizationTeamMemberRead,
14+
15+
Schema: map[string]*schema.Schema{
16+
"organization": {
17+
Type: schema.TypeString,
18+
Required: true,
19+
},
20+
"team": {
21+
Type: schema.TypeString,
22+
Required: true,
23+
},
24+
"users": {
25+
Type: schema.TypeSet,
26+
Computed: true,
27+
Elem: &schema.Resource{
28+
Schema: map[string]*schema.Schema{
29+
"type": {
30+
Type: schema.TypeString,
31+
Optional: true,
32+
},
33+
"name": {
34+
Type: schema.TypeString,
35+
Optional: true,
36+
},
37+
"url": {
38+
Type: schema.TypeString,
39+
Optional: true,
40+
},
41+
"icon_url": {
42+
Type: schema.TypeString,
43+
Optional: true,
44+
},
45+
},
46+
},
47+
},
48+
},
49+
}
50+
}
51+
52+
func dataSourceOrganizationTeamMemberRead(d *schema.ResourceData, meta interface{}) error {
53+
client := meta.(*Config).client
54+
55+
organization := d.Get("organization").(string)
56+
team := d.Get("team").(string)
57+
58+
log.Printf("[DEBUG] dataSourceOrganizationTeamMemberRead: %s", organization)
59+
60+
cfg := &go_deploygate.ListOrganizationTeamMembersRequest{
61+
Organization: organization,
62+
Team: team,
63+
}
64+
65+
resp, err := client.ListOrganizationTeamMembers(cfg)
66+
67+
if err != nil {
68+
return err
69+
}
70+
71+
d.SetId(fmt.Sprintf("%s/%s", organization, team))
72+
d.Set("users", resp.Users)
73+
74+
return nil
75+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package deploygate
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
9+
)
10+
11+
func Test_DataSourceOrganizationTeamMember_basic(t *testing.T) {
12+
testWithVCR(t, resource.TestCase{
13+
PreCheck: func() { Test_DGPreCheck(t) },
14+
Steps: []resource.TestStep{
15+
{
16+
Config: testDataSourceOrganizationTeamMemberConfig,
17+
Check: resource.ComposeTestCheckFunc(
18+
testDataSourceOrganizationTeamMember("data.deploygate_organization_team_member.current"),
19+
),
20+
},
21+
},
22+
})
23+
}
24+
25+
func testDataSourceOrganizationTeamMember(n string) resource.TestCheckFunc {
26+
return func(s *terraform.State) error {
27+
rs, ok := s.RootModule().Resources[n]
28+
if !ok {
29+
return fmt.Errorf("Can't find resource: %s", n)
30+
}
31+
32+
if rs.Primary.ID == "" {
33+
return fmt.Errorf("Resource ID not set")
34+
}
35+
36+
if rs.Primary.Attributes["organization"] == "" {
37+
return fmt.Errorf("organization expected to not be nil")
38+
}
39+
40+
if rs.Primary.Attributes["team"] == "" {
41+
return fmt.Errorf("team expected to not be nil")
42+
}
43+
44+
return nil
45+
}
46+
}
47+
48+
const testDataSourceOrganizationTeamMemberConfig = `
49+
provider "deploygate" {
50+
api_key = var.organization_api_key
51+
}
52+
53+
variable "organization_api_key" {
54+
type = string
55+
}
56+
57+
data "deploygate_organization_team_member" "current" {
58+
organization = var.organization
59+
team = var.team
60+
}
61+
62+
variable "organization" {
63+
type = string
64+
}
65+
66+
variable "team" {
67+
type = string
68+
}
69+
`
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: ""
6+
form: {}
7+
headers:
8+
Accept:
9+
- application/json
10+
Content-Type:
11+
- application/x-www-form-urlencoded
12+
User-Agent:
13+
- GoDeployGate (+github.com/fnaoto/go_deploygate; go1.17.11)
14+
url: https://deploygate.com/api/enterprises/test-enterprise-fnaoto/users
15+
method: GET
16+
response:
17+
body: '{"error":false,"users":[{"type":"User","name":"naoto-fukuda-test","icon_url":"https://secure.gravatar.com/avatar/b8522f0e74e1673596e2c15dca95c04a?s=218\u0026d=mm","url":"https://deploygate.com/users/naoto-fukuda-test","full_name":null,"email":"dummy.email","role":"Admin","created_at":"2022-11-17T20:49:14.000+09:00","last_access_at":"2022-12-01T13:43:51.000+09:00"},{"type":"User","name":"naoto-fukuda","icon_url":"https://secure.gravatar.com/avatar/77329ff2f492bb519f6f11a7bd27d568?s=218\u0026d=mm","url":"https://deploygate.com/users/naoto-fukuda","full_name":null,"email":"dummy.email","role":"General","created_at":"2022-12-01T11:54:29.000+09:00","last_access_at":"2022-12-01T11:57:28.000+09:00"}]}'
18+
headers: {}
19+
status: 200 OK
20+
code: 200
21+
duration: ""
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: ""
6+
form: {}
7+
headers:
8+
Accept:
9+
- application/json
10+
Content-Type:
11+
- application/x-www-form-urlencoded
12+
User-Agent:
13+
- GoDeployGate (+github.com/fnaoto/go_deploygate; go1.17.11)
14+
url: https://deploygate.com/api/enterprises/test-enterprise-fnaoto/users
15+
method: GET
16+
response:
17+
body: '{"error":false,"users":[{"type":"User","name":"naoto-fukuda-test","icon_url":"https://secure.gravatar.com/avatar/b8522f0e74e1673596e2c15dca95c04a?s=218\u0026d=mm","url":"https://deploygate.com/users/naoto-fukuda-test","full_name":null,"email":"dummy.email","role":"Admin","created_at":"2022-11-17T20:49:14.000+09:00","last_access_at":"2022-12-01T13:43:51.000+09:00"},{"type":"User","name":"naoto-fukuda","icon_url":"https://secure.gravatar.com/avatar/77329ff2f492bb519f6f11a7bd27d568?s=218\u0026d=mm","url":"https://deploygate.com/users/naoto-fukuda","full_name":null,"email":"dummy.email","role":"General","created_at":"2022-12-01T11:54:29.000+09:00","last_access_at":"2022-12-01T11:57:28.000+09:00"}]}'
18+
headers: {}
19+
status: 200 OK
20+
code: 200
21+
duration: ""

0 commit comments

Comments
 (0)