Skip to content

Commit 6318a74

Browse files
authored
Merge pull request #30 from fnaoto/2022-12-08
2022 12 08
2 parents 8ebdd42 + 2901c1f commit 6318a74

File tree

22 files changed

+298
-57
lines changed

22 files changed

+298
-57
lines changed

.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
exoprt TF_VAR_team=""
44
export TF_VAR_organization=""
5+
export TF_VAR_organization_only=""
6+
export TF_VAR_organization_in_enterprise=""
57
export TF_VAR_organization_api_key=""
68

79
# For enterprise

.terraformrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
provider_installation {
2+
dev_overrides {
3+
"fnaoto/deploygate" = "~/.terraform.d/plugins/darwin_amd64/terraform-provider-deploygate"
4+
}
5+
6+
direct {}
7+
}

Makefile

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,25 @@
1-
TEST?=$$(go list ./... | grep -v 'vendor')
21
NAME=deploygate
32
BINARY=terraform-provider-${NAME}
4-
VERSION=0.1
53
OS_ARCH?=darwin_amd64
6-
EXAMPLES=examples
4+
PROVIDER_DIR=~/.terraform.d/plugins/${OS_ARCH}
75

86
default: install
97

108
build:
11-
go build -o ${BINARY}
12-
13-
release:
14-
GOOS=darwin GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_darwin_amd64
15-
GOOS=darwin GOARCH=arm64 go build -o ./bin/${BINARY}_${VERSION}_darwin_arm64
16-
GOOS=freebsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_freebsd_386
17-
GOOS=freebsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_freebsd_amd64
18-
GOOS=freebsd GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_freebsd_arm
19-
GOOS=linux GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_linux_386
20-
GOOS=linux GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_linux_amd64
21-
GOOS=linux GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_linux_arm
22-
GOOS=openbsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_openbsd_386
23-
GOOS=openbsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_openbsd_amd64
24-
GOOS=solaris GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_solaris_amd64
25-
GOOS=windows GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_windows_386
26-
GOOS=windows GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_windows_amd64
9+
go build ${BINARY}
2710

2811
install: build
29-
mkdir -p ~/.terraform.d/plugins/${OS_ARCH}
30-
mv ${BINARY} ~/.terraform.d/plugins/${OS_ARCH}
12+
mkdir -p $(PROVIDER_DIR)
13+
mv ${BINARY} $(PROVIDER_DIR)
14+
cp .terraformrc ~
3115

32-
test:
33-
go test $(TEST) || exit 1
34-
echo $(TEST) | xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4
16+
test:
17+
go test -v $(TESTARGS) -cover -timeout=120s -parallel=4 ./...
3518

3619
testacc: install
37-
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
38-
39-
examples: install
40-
terraform init $(EXAMPLES)
41-
terraform plan $(EXAMPLES)
42-
terraform apply $(EXAMPLES)
43-
terraform destroy $(EXAMPLES)
20+
TF_ACC=1 go test -v $(TESTARGS) -cover -timeout 120m ./...
4421

4522
docs:
4623
go generate ./...
4724

48-
.PHONY: docs examples testacc test install build release
25+
.PHONY: docs examples testacc test install build

deploygate/provider.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package deploygate
22

33
import (
4+
"context"
5+
46
go_deploygate "github.com/fnaoto/go_deploygate"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
58
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
69
)
710

@@ -29,12 +32,12 @@ func Provider() *schema.Provider {
2932
},
3033
}
3134

32-
p.ConfigureFunc = providerConfigure(p)
35+
p.ConfigureContextFunc = providerConfigure(p)
3336
return p
3437
}
3538

36-
func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
37-
return func(d *schema.ResourceData) (interface{}, error) {
39+
func providerConfigure(p *schema.Provider) schema.ConfigureContextFunc {
40+
return func(_ context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
3841
config := Config{
3942
clientConfig: go_deploygate.ClientConfig{
4043
ApiKey: d.Get("api_key").(string),
@@ -43,7 +46,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
4346

4447
err := config.initClient()
4548
if err != nil {
46-
return nil, err
49+
return nil, diag.FromErr(err)
4750
}
4851

4952
return config.client, nil

deploygate/provider_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/dnaeon/go-vcr/cassette"
1212
"github.com/dnaeon/go-vcr/recorder"
1313
go_deploygate "github.com/fnaoto/go_deploygate"
14+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1415
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1516
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1617
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
@@ -51,7 +52,7 @@ func Test_DGPreCheck(t *testing.T) {
5152

5253
func initProvider(t *testing.T) map[string]*schema.Provider {
5354
testDGProvider = Provider()
54-
testDGProvider.ConfigureFunc = providerConfigureVCR(testDGProvider, t)
55+
testDGProvider.ConfigureContextFunc = providerConfigureVCR(testDGProvider, t)
5556

5657
testDGProviders = map[string]*schema.Provider{
5758
ProviderNameDG: testDGProvider,
@@ -60,8 +61,8 @@ func initProvider(t *testing.T) map[string]*schema.Provider {
6061
return testDGProviders
6162
}
6263

63-
func providerConfigureVCR(p *schema.Provider, t *testing.T) schema.ConfigureFunc {
64-
return func(d *schema.ResourceData) (interface{}, error) {
64+
func providerConfigureVCR(p *schema.Provider, t *testing.T) schema.ConfigureContextFunc {
65+
return func(_ context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
6566
config := &Config{
6667
clientConfig: go_deploygate.ClientConfig{
6768
ApiKey: d.Get("api_key").(string),
@@ -70,14 +71,14 @@ func providerConfigureVCR(p *schema.Provider, t *testing.T) schema.ConfigureFunc
7071

7172
err := config.initClient()
7273
if err != nil {
73-
return nil, err
74+
return nil, diag.FromErr(err)
7475
}
7576

7677
fixture := filepath.Join(FixtureBasePath, t.Name(), strconv.Itoa(len(testDGConfigs)))
7778

7879
rec, err := recorder.New(fixture)
7980
if err != nil {
80-
return nil, err
81+
return nil, diag.FromErr(err)
8182
}
8283

8384
rec.AddSaveFilter(func(i *cassette.Interaction) error {

docs/index.md

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
---
2-
# generated by https://github.com/hashicorp/terraform-plugin-docs
32
page_title: "deploygate Provider"
4-
subcategory: ""
53
description: |-
6-
4+
The DeployGate provider is used to manage enteprise/organization/team members.
75
---
86

9-
# deploygate Provider
7+
# DeployGate Provider
108

9+
The deploygate is distribution platform for in-development mobile app (iOS and Android),
10+
delivering apps for enteprise/organization/team members.
1111

12+
Try the [deploygate](https://deploygate.com/).
1213

1314
## Example Usage
1415

16+
Terraform 0.13 and later:
17+
1518
```terraform
1619
terraform {
1720
required_providers {
@@ -21,6 +24,8 @@ terraform {
2124
}
2225
}
2326
27+
# Provider for organization api key
28+
2429
provider "deploygate" {
2530
alias = "organization"
2631
api_key = var.organization_api_key
@@ -30,6 +35,8 @@ variable "organization_api_key" {
3035
type = string
3136
}
3237
38+
# Provider for enterprise api key
39+
3340
provider "deploygate" {
3441
alias = "enterprise"
3542
api_key = var.enterprise_api_key
@@ -38,9 +45,43 @@ provider "deploygate" {
3845
variable "enterprise_api_key" {
3946
type = string
4047
}
48+
49+
# Provider via environment variable which DG_API_KEY
50+
#
51+
## export DG_API_KEY="< api_key >"
52+
53+
provider "deploygate" {}
54+
```
55+
56+
## Authentication
57+
58+
The deploygate providing credentials for authentication.
59+
60+
- [Organization API Key](https://docs.deploygate.com/docs/organization)
61+
- [Enterprise API Key](https://docs.deploygate.com/docs/enterprise)
62+
63+
### Set credentials with provider
64+
65+
API Key can be adding an `api_key`, in-line in the deploygate provider block.
66+
67+
```terraform
68+
provider "deploygate" {
69+
api_key = "< api_key >"
70+
}
71+
```
72+
73+
### Set credentials with environment variable
74+
75+
You can provide api_key via `DG_API_KEY` which environment variable.
76+
77+
```shell
78+
$ export DG_API_KEY="< api_key >"
79+
```
80+
81+
```terraform
82+
provider "deploygate" {}
4183
```
4284

43-
<!-- schema generated by tfplugindocs -->
4485
## Schema
4586

4687
### Optional

docs/resources/organization_member.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ Manages a organization member resource.
1313
## Example Usage
1414

1515
```terraform
16+
# Variables
17+
18+
provider "deploygate" {
19+
alias = "enterprise"
20+
api_key = var.enterprise_api_key
21+
}
22+
23+
variable "enterprise_api_key" {
24+
type = string
25+
}
26+
1627
provider "deploygate" {
1728
alias = "organization"
1829
api_key = var.organization_api_key
@@ -22,17 +33,47 @@ variable "organization_api_key" {
2233
type = string
2334
}
2435
25-
variable "organization" {
36+
variable "organization_in_enterprise" {
37+
type = string
38+
}
39+
40+
variable "organization_only" {
2641
type = string
2742
}
2843
2944
variable "add_member_name" {
3045
type = string
3146
}
3247
33-
resource "deploygate_organization_member" "current" {
48+
# For enterprise organization.
49+
50+
resource "deploygate_enterprise_member" "enterprise" {
51+
provider = deploygate.enterprise
52+
enterprise = var.enterprise
53+
54+
users {
55+
name = var.add_member_name
56+
}
57+
}
58+
59+
resource "deploygate_organization_member" "enterprise" {
60+
provider = deploygate.enterprise
61+
organization = var.organization_in_enterprise
62+
63+
members {
64+
name = var.add_member_name
65+
}
66+
67+
depends_on = [
68+
deploygate_enterprise_member.enterprise
69+
]
70+
}
71+
72+
# For Organization only
73+
74+
resource "deploygate_organization_member" "organization" {
3475
provider = deploygate.organization
35-
organization = var.organization
76+
organization = var.organization_only
3677
3778
members {
3879
name = var.add_member_name

docs/resources/organization_team_member.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ variable "add_member_name" {
3434
type = string
3535
}
3636
37+
resource "deploygate_organization_member" "current" {
38+
provider = deploygate.organization
39+
organization = var.organization
40+
41+
members {
42+
name = var.add_member_name
43+
}
44+
}
45+
3746
resource "deploygate_organization_team_member" "current" {
3847
provider = deploygate.organization
3948
organization = var.organization
@@ -42,6 +51,10 @@ resource "deploygate_organization_team_member" "current" {
4251
users {
4352
name = var.add_member_name
4453
}
54+
55+
depends_on = [
56+
deploygate_organization_member.current
57+
]
4558
}
4659
```
4760

examples/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ terraform.tfvars
22
.terraform/
33
*.log
44
*.tfstate
5-
*.backup
5+
*.backup
6+
7+
.terraform.lock.hcl

examples/data-sources/deploygate_enterprise_member/data-source.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
provider "deploygate" {
32
alias = "enterprise"
43
api_key = var.enterprise_api_key

0 commit comments

Comments
 (0)