Skip to content

Commit df55e05

Browse files
committed
Add the contentstack_global_field resource.
1 parent d4a76d5 commit df55e05

File tree

11 files changed

+421
-10
lines changed

11 files changed

+421
-10
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.terraform/
22
.terraform.lock.hcl
33
*.tfstate
4+
*.backup
45

56
/main.tf
6-
terraform-provider-contentstack_*
7+
/terraform-provider-contentstack_*
8+
/terraform-provider-contentstack

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.1.1 (2022-06-03)
2+
3+
Add the `contentstack_global_field` resource.
4+
5+
16
## 0.1.0 (2022-06-03)
27

38
Initial release of the contentstack terraform provider. It currently only

docs/resources/global_field.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "contentstack_global_field Resource - terraform-provider-contentstack"
4+
subcategory: ""
5+
description: |-
6+
A Global field is a reusable field (or group of fields) that you can
7+
define once and reuse in any content type within your stack. This
8+
eliminates the need (and thereby time and efforts) to create the same
9+
set of fields repeatedly in multiple content types.
10+
---
11+
12+
# contentstack_global_field (Resource)
13+
14+
A Global field is a reusable field (or group of fields) that you can
15+
define once and reuse in any content type within your stack. This
16+
eliminates the need (and thereby time and efforts) to create the same
17+
set of fields repeatedly in multiple content types.
18+
19+
## Example Usage
20+
21+
```terraform
22+
terraform {
23+
required_providers {
24+
contentstack = {
25+
source = "labd/contentstack"
26+
}
27+
}
28+
}
29+
30+
provider "contentstack" {
31+
base_url = "https://eu-api.contentstack.com/"
32+
api_key = "<api_key>"
33+
management_token = "<token>"
34+
}
35+
36+
37+
resource "contentstack_global_field" "my_field" {
38+
title = "test something"
39+
uid = "foobar"
40+
description = "someting"
41+
maintain_revisions = true
42+
43+
schema = jsonencode(jsondecode(<<JSON
44+
[
45+
{
46+
"display_name": "Name",
47+
"uid": "name",
48+
"multiple": false,
49+
"non_localizable": false,
50+
"unique": false,
51+
"mandatory": false,
52+
"data_type": "text"
53+
},
54+
{
55+
"data_type": "text",
56+
"display_name": "Rich text editor",
57+
"uid": "description",
58+
"field_metadata": {
59+
"allow_rich_text": true,
60+
"description": "foobar",
61+
"multiline": false,
62+
"rich_text_type": "advanced",
63+
"options": [],
64+
"version": 3
65+
},
66+
"multiple": false,
67+
"non_localizable": false,
68+
"mandatory": false,
69+
"unique": false
70+
}
71+
]
72+
JSON
73+
))
74+
}
75+
```
76+
77+
<!-- schema generated by tfplugindocs -->
78+
## Schema
79+
80+
### Required
81+
82+
- `title` (String)
83+
- `uid` (String)
84+
85+
### Optional
86+
87+
- `description` (String)
88+
- `maintain_revisions` (Boolean)
89+
- `schema` (String) The schema as JSON. Use jsonencode(jsonecode(<schema>)) to work around wrong changes.
90+
91+

docs/resources/webhook.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,46 @@ description: |-
1212
A webhook is a user-defined HTTP callback. It is a mechanism that sends
1313
real-time information to any third-party app or service.
1414

15-
15+
## Example Usage
16+
17+
```terraform
18+
terraform {
19+
required_providers {
20+
contentstack = {
21+
source = "labd/contentstack"
22+
}
23+
}
24+
}
25+
26+
provider "contentstack" {
27+
base_url = "https://eu-api.contentstack.com/"
28+
api_key = "<api_key>"
29+
management_token = "<token>"
30+
}
31+
32+
33+
resource "contentstack_webhook" "mywebhook" {
34+
name = "test"
35+
36+
destination {
37+
target_url = "http://example.com"
38+
http_basic_auth = "user"
39+
http_basic_password = "password"
40+
41+
custom_headers = [{
42+
header_name = "Custom"
43+
value = "testing"
44+
}]
45+
}
46+
47+
channels = ["assets.create"]
48+
branches = ["main"]
49+
50+
retry_policy = "manual"
51+
disabled = false
52+
concise_payload = true
53+
}
54+
```
1655

1756
<!-- schema generated by tfplugindocs -->
1857
## Schema
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
terraform {
3+
required_providers {
4+
contentstack = {
5+
source = "labd/contentstack"
6+
}
7+
}
8+
}
9+
10+
provider "contentstack" {
11+
base_url = "https://eu-api.contentstack.com/"
12+
api_key = "<api_key>"
13+
management_token = "<token>"
14+
}
15+
16+
17+
resource "contentstack_global_field" "my_field" {
18+
title = "test something"
19+
uid = "foobar"
20+
description = "someting"
21+
maintain_revisions = true
22+
23+
schema = jsonencode(jsondecode(<<JSON
24+
[
25+
{
26+
"display_name": "Name",
27+
"uid": "name",
28+
"multiple": false,
29+
"non_localizable": false,
30+
"unique": false,
31+
"mandatory": false,
32+
"data_type": "text"
33+
},
34+
{
35+
"data_type": "text",
36+
"display_name": "Rich text editor",
37+
"uid": "description",
38+
"field_metadata": {
39+
"allow_rich_text": true,
40+
"description": "foobar",
41+
"multiline": false,
42+
"rich_text_type": "advanced",
43+
"options": [],
44+
"version": 3
45+
},
46+
"multiple": false,
47+
"non_localizable": false,
48+
"mandatory": false,
49+
"unique": false
50+
}
51+
]
52+
JSON
53+
))
54+
}

examples/resources/contentstack_webhook/main.tf renamed to examples/resources/contentstack_webhook/resource.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
terraform {
33
required_providers {
44
contentstack = {
5-
source = "labd/contentstack"
6-
version = "0.1.0"
5+
source = "labd/contentstack"
76
}
87
}
98
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/hashicorp/terraform-plugin-docs v0.9.0
77
github.com/hashicorp/terraform-plugin-framework v0.8.1-0.20220531184835-f0051665855e
88
github.com/hashicorp/terraform-plugin-go v0.9.1
9-
github.com/labd/contentstack-go-sdk v0.0.0-20220603122001-6c586b525fb3
9+
github.com/labd/contentstack-go-sdk v0.0.0-20220603150426-b675b0bd2a10
1010
)
1111

1212
// replace github.com/labd/contentstack-go-sdk => ../contentstack-go-sdk

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
160160
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
161161
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
162162
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
163-
github.com/labd/contentstack-go-sdk v0.0.0-20220603122001-6c586b525fb3 h1:87UmyMNZtc0KFsW+d6SNXhObOXyvzOQ+zv7JW8Fi/1Y=
164-
github.com/labd/contentstack-go-sdk v0.0.0-20220603122001-6c586b525fb3/go.mod h1:2pN/o4bC/yK/X+n/E/nOHvJssM0kLEUURtYZhsd3NOY=
163+
github.com/labd/contentstack-go-sdk v0.0.0-20220603150426-b675b0bd2a10 h1:7M8co9vvMcJZJApOorfPCdhGlocGWtR+0gfarOGoxuk=
164+
github.com/labd/contentstack-go-sdk v0.0.0-20220603150426-b675b0bd2a10/go.mod h1:2pN/o4bC/yK/X+n/E/nOHvJssM0kLEUURtYZhsd3NOY=
165165
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
166166
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
167167
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=

internal/provider/errors.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ func processRemoteError(e error) diag.Diagnostics {
1515

1616
case *management.ErrorMessage:
1717
errors := []string{}
18-
for _, fieldErrors := range err.Errors {
18+
for fieldName, fieldErrors := range err.Errors {
1919
for _, msg := range fieldErrors {
20-
errors = append(errors, fmt.Sprintf(" - %s", msg))
20+
errors = append(errors, fmt.Sprintf(" %s - %s", fieldName, msg))
2121
}
2222
}
2323
diags.AddError(err.ErrorMessage, strings.Join(errors, "\n"))

internal/provider/provider.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ func (p *provider) Configure(ctx context.Context, req tfsdk.ConfigureProviderReq
105105
// GetResources - Defines provider resources
106106
func (p *provider) GetResources(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) {
107107
return map[string]tfsdk.ResourceType{
108-
"contentstack_webhook": resourceWebhookType{},
108+
"contentstack_webhook": resourceWebhookType{},
109+
"contentstack_global_field": resourceGlobalFieldType{},
109110
}, nil
110111
}
111112

0 commit comments

Comments
 (0)