Skip to content

Commit

Permalink
Add the contentstack_global_field resource.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvantellingen committed Jun 3, 2022
1 parent d4a76d5 commit df55e05
Show file tree
Hide file tree
Showing 11 changed files with 421 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.terraform/
.terraform.lock.hcl
*.tfstate
*.backup

/main.tf
terraform-provider-contentstack_*
/terraform-provider-contentstack_*
/terraform-provider-contentstack
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.1.1 (2022-06-03)

Add the `contentstack_global_field` resource.


## 0.1.0 (2022-06-03)

Initial release of the contentstack terraform provider. It currently only
Expand Down
91 changes: 91 additions & 0 deletions docs/resources/global_field.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "contentstack_global_field Resource - terraform-provider-contentstack"
subcategory: ""
description: |-
A Global field is a reusable field (or group of fields) that you can
define once and reuse in any content type within your stack. This
eliminates the need (and thereby time and efforts) to create the same
set of fields repeatedly in multiple content types.
---

# contentstack_global_field (Resource)

A Global field is a reusable field (or group of fields) that you can
define once and reuse in any content type within your stack. This
eliminates the need (and thereby time and efforts) to create the same
set of fields repeatedly in multiple content types.

## Example Usage

```terraform
terraform {
required_providers {
contentstack = {
source = "labd/contentstack"
}
}
}
provider "contentstack" {
base_url = "https://eu-api.contentstack.com/"
api_key = "<api_key>"
management_token = "<token>"
}
resource "contentstack_global_field" "my_field" {
title = "test something"
uid = "foobar"
description = "someting"
maintain_revisions = true
schema = jsonencode(jsondecode(<<JSON
[
{
"display_name": "Name",
"uid": "name",
"multiple": false,
"non_localizable": false,
"unique": false,
"mandatory": false,
"data_type": "text"
},
{
"data_type": "text",
"display_name": "Rich text editor",
"uid": "description",
"field_metadata": {
"allow_rich_text": true,
"description": "foobar",
"multiline": false,
"rich_text_type": "advanced",
"options": [],
"version": 3
},
"multiple": false,
"non_localizable": false,
"mandatory": false,
"unique": false
}
]
JSON
))
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `title` (String)
- `uid` (String)

### Optional

- `description` (String)
- `maintain_revisions` (Boolean)
- `schema` (String) The schema as JSON. Use jsonencode(jsonecode(<schema>)) to work around wrong changes.


41 changes: 40 additions & 1 deletion docs/resources/webhook.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,46 @@ description: |-
A webhook is a user-defined HTTP callback. It is a mechanism that sends
real-time information to any third-party app or service.


## Example Usage

```terraform
terraform {
required_providers {
contentstack = {
source = "labd/contentstack"
}
}
}
provider "contentstack" {
base_url = "https://eu-api.contentstack.com/"
api_key = "<api_key>"
management_token = "<token>"
}
resource "contentstack_webhook" "mywebhook" {
name = "test"
destination {
target_url = "http://example.com"
http_basic_auth = "user"
http_basic_password = "password"
custom_headers = [{
header_name = "Custom"
value = "testing"
}]
}
channels = ["assets.create"]
branches = ["main"]
retry_policy = "manual"
disabled = false
concise_payload = true
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
54 changes: 54 additions & 0 deletions examples/resources/contentstack_global_field/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

terraform {
required_providers {
contentstack = {
source = "labd/contentstack"
}
}
}

provider "contentstack" {
base_url = "https://eu-api.contentstack.com/"
api_key = "<api_key>"
management_token = "<token>"
}


resource "contentstack_global_field" "my_field" {
title = "test something"
uid = "foobar"
description = "someting"
maintain_revisions = true

schema = jsonencode(jsondecode(<<JSON
[
{
"display_name": "Name",
"uid": "name",
"multiple": false,
"non_localizable": false,
"unique": false,
"mandatory": false,
"data_type": "text"
},
{
"data_type": "text",
"display_name": "Rich text editor",
"uid": "description",
"field_metadata": {
"allow_rich_text": true,
"description": "foobar",
"multiline": false,
"rich_text_type": "advanced",
"options": [],
"version": 3
},
"multiple": false,
"non_localizable": false,
"mandatory": false,
"unique": false
}
]
JSON
))
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
terraform {
required_providers {
contentstack = {
source = "labd/contentstack"
version = "0.1.0"
source = "labd/contentstack"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/hashicorp/terraform-plugin-docs v0.9.0
github.com/hashicorp/terraform-plugin-framework v0.8.1-0.20220531184835-f0051665855e
github.com/hashicorp/terraform-plugin-go v0.9.1
github.com/labd/contentstack-go-sdk v0.0.0-20220603122001-6c586b525fb3
github.com/labd/contentstack-go-sdk v0.0.0-20220603150426-b675b0bd2a10
)

// replace github.com/labd/contentstack-go-sdk => ../contentstack-go-sdk
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/labd/contentstack-go-sdk v0.0.0-20220603122001-6c586b525fb3 h1:87UmyMNZtc0KFsW+d6SNXhObOXyvzOQ+zv7JW8Fi/1Y=
github.com/labd/contentstack-go-sdk v0.0.0-20220603122001-6c586b525fb3/go.mod h1:2pN/o4bC/yK/X+n/E/nOHvJssM0kLEUURtYZhsd3NOY=
github.com/labd/contentstack-go-sdk v0.0.0-20220603150426-b675b0bd2a10 h1:7M8co9vvMcJZJApOorfPCdhGlocGWtR+0gfarOGoxuk=
github.com/labd/contentstack-go-sdk v0.0.0-20220603150426-b675b0bd2a10/go.mod h1:2pN/o4bC/yK/X+n/E/nOHvJssM0kLEUURtYZhsd3NOY=
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ func processRemoteError(e error) diag.Diagnostics {

case *management.ErrorMessage:
errors := []string{}
for _, fieldErrors := range err.Errors {
for fieldName, fieldErrors := range err.Errors {
for _, msg := range fieldErrors {
errors = append(errors, fmt.Sprintf(" - %s", msg))
errors = append(errors, fmt.Sprintf(" %s - %s", fieldName, msg))
}
}
diags.AddError(err.ErrorMessage, strings.Join(errors, "\n"))
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ func (p *provider) Configure(ctx context.Context, req tfsdk.ConfigureProviderReq
// GetResources - Defines provider resources
func (p *provider) GetResources(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) {
return map[string]tfsdk.ResourceType{
"contentstack_webhook": resourceWebhookType{},
"contentstack_webhook": resourceWebhookType{},
"contentstack_global_field": resourceGlobalFieldType{},
}, nil
}

Expand Down
Loading

0 comments on commit df55e05

Please sign in to comment.