From eae1337bb3e0a7f8dc76f6261dfc829ef7a12e80 Mon Sep 17 00:00:00 2001 From: Nicholas Ting Date: Thu, 14 Sep 2023 23:24:30 +1000 Subject: [PATCH 1/9] feat: update resource create to handle integer and numbers --- contentful/resource_contentful_entry.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/contentful/resource_contentful_entry.go b/contentful/resource_contentful_entry.go index 9fe3fa1..b650657 100644 --- a/contentful/resource_contentful_entry.go +++ b/contentful/resource_contentful_entry.go @@ -91,8 +91,23 @@ func resourceCreateEntry(ctx context.Context, d *schema.ResourceData, env *conte rawField := d.Get("field").([]interface{}) for i := 0; i < len(rawField); i++ { field := rawField[i].(map[string]interface{}) + content := field["content"] + + // Check the type of content and convert to integer if it's an integer. + var fieldValue interface{} + switch content.(type) { + case int: + fieldValue = content.(int) + case float64: + // Handle float64 as well, in case content is a floating-point number. + fieldValue = int(content.(float64)) + default: + // If it's not an integer, assume it's a string. + fieldValue = content.(string) + } + fieldProperties[field["id"].(string)] = map[string]interface{}{} - fieldProperties[field["id"].(string)].(map[string]interface{})[field["locale"].(string)] = field["content"].(string) + fieldProperties[field["id"].(string)].(map[string]interface{})[field["locale"].(string)] = fieldValue } entry := &contentful.Entry{ From fabf1645d4fe9c8a9c83f67adfd90600c545fec2 Mon Sep 17 00:00:00 2001 From: Nicholas Ting Date: Thu, 14 Sep 2023 23:36:40 +1000 Subject: [PATCH 2/9] feat: go release --- .goreleaser.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index d11e802..6ca0a02 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -41,18 +41,18 @@ checksum: name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json' name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS' algorithm: sha256 -signs: - - artifacts: checksum - args: - # if you are using this in a GitHub action or some other automated pipeline, you - # need to pass the batch flag to indicate its not interactive. - - "--batch" - - "--local-user" - - "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key - - "--output" - - "${signature}" - - "--detach-sign" - - "${artifact}" +# signs: +# - artifacts: checksum +# args: +# # if you are using this in a GitHub action or some other automated pipeline, you +# # need to pass the batch flag to indicate its not interactive. +# - "--batch" +# - "--local-user" +# - "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key +# - "--output" +# - "${signature}" +# - "--detach-sign" +# - "${artifact}" release: extra_files: - glob: 'terraform-registry-manifest.json' From 2593ab329ad04729c3373092712203f4e87c661f Mon Sep 17 00:00:00 2001 From: Nicholas Ting Date: Thu, 14 Sep 2023 23:42:44 +1000 Subject: [PATCH 3/9] feat: added gpg fingerprint --- .goreleaser.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 6ca0a02..d11e802 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -41,18 +41,18 @@ checksum: name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json' name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS' algorithm: sha256 -# signs: -# - artifacts: checksum -# args: -# # if you are using this in a GitHub action or some other automated pipeline, you -# # need to pass the batch flag to indicate its not interactive. -# - "--batch" -# - "--local-user" -# - "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key -# - "--output" -# - "${signature}" -# - "--detach-sign" -# - "${artifact}" +signs: + - artifacts: checksum + args: + # if you are using this in a GitHub action or some other automated pipeline, you + # need to pass the batch flag to indicate its not interactive. + - "--batch" + - "--local-user" + - "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key + - "--output" + - "${signature}" + - "--detach-sign" + - "${artifact}" release: extra_files: - glob: 'terraform-registry-manifest.json' From 19525cb073dc88668b0b2c7028133954c1e21068 Mon Sep 17 00:00:00 2001 From: Nicholas Ting Date: Thu, 14 Sep 2023 23:48:59 +1000 Subject: [PATCH 4/9] feat: release --- .github/workflows/release.yaml | 4 +- .github/workflows/test.yaml | 102 ++++++++++++++++----------------- README.md | 2 +- 3 files changed, 54 insertions(+), 54 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 08f6fc7..2547b29 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -12,8 +12,8 @@ name: release on: push: - tags: - - 'v*' + branches: + - main permissions: contents: write jobs: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e9635f8..3fdfd63 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,51 +1,51 @@ -name: Test - -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: ^1.16 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v3 - - - name: Get dependencies - run: | - go mod download - - - name: Test - env: - CONTENTFUL_MANAGEMENT_TOKEN: ${{ secrets.CONTENTFUL_MANAGEMENT_TOKEN }} - CONTENTFUL_ORGANIZATION_ID: ${{ secrets.CONTENTFUL_ORGANIZATION_ID }} - SPACE_ID: ${{ secrets.SPACE_ID }} - ENV_ID: ${{ secrets.ENV_ID }} - run: | - make testacc - - - name: Convert coverage to lcov - uses: jandelgado/gcov2lcov-action@v1.0.0 - if: github.ref == 'refs/heads/main' - with: - infile: cover.out - outfile: cover.lcov - - - name: Coveralls - uses: coverallsapp/github-action@master - if: github.ref == 'refs/heads/main' - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: cover.lcov +# name: Test + +# on: +# push: +# branches: +# - main +# pull_request: +# branches: +# - main + +# jobs: +# build: +# name: Build +# runs-on: ubuntu-latest +# steps: + +# - name: Set up Go 1.x +# uses: actions/setup-go@v2 +# with: +# go-version: ^1.16 +# id: go + +# - name: Check out code into the Go module directory +# uses: actions/checkout@v3 + +# - name: Get dependencies +# run: | +# go mod download + +# - name: Test +# env: +# CONTENTFUL_MANAGEMENT_TOKEN: ${{ secrets.CONTENTFUL_MANAGEMENT_TOKEN }} +# CONTENTFUL_ORGANIZATION_ID: ${{ secrets.CONTENTFUL_ORGANIZATION_ID }} +# SPACE_ID: ${{ secrets.SPACE_ID }} +# ENV_ID: ${{ secrets.ENV_ID }} +# run: | +# make testacc + +# - name: Convert coverage to lcov +# uses: jandelgado/gcov2lcov-action@v1.0.0 +# if: github.ref == 'refs/heads/main' +# with: +# infile: cover.out +# outfile: cover.lcov + +# - name: Coveralls +# uses: coverallsapp/github-action@master +# if: github.ref == 'refs/heads/main' +# with: +# github-token: ${{ secrets.GITHUB_TOKEN }} +# path-to-lcov: cover.lcov diff --git a/README.md b/README.md index 74dcdf3..18b5aef 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![codecov](https://coveralls.io/repos/github/kitagry/terraform-provider-contentful/badge.svg?branch=main)](https://coveralls.io/github/kitagry/terraform-provider-contentful?branch=main) [![license](https://img.shields.io/github/license/kitagry/terraform-provider-contentful.svg)](https://github.com/kitagry/terraform-provider-contentful/blob/master/LICENSE) -Terraform Provider for [Contentful's](https://www.contentful.com) Content Management API +Terraform Provider for [Contentful's](https://www.contentful.com) Content Management API - Add ons # About From e3b1e76b553822a4001c78306281d97693fb257a Mon Sep 17 00:00:00 2001 From: Nicholas Ting Date: Thu, 14 Sep 2023 23:55:55 +1000 Subject: [PATCH 5/9] fix: tags --- .github/workflows/release.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2547b29..08f6fc7 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -12,8 +12,8 @@ name: release on: push: - branches: - - main + tags: + - 'v*' permissions: contents: write jobs: From b550373fcf6ee5b9d0b863a60e6bd7c1548c6dda Mon Sep 17 00:00:00 2001 From: Nicholas Ting Date: Fri, 15 Sep 2023 00:17:59 +1000 Subject: [PATCH 6/9] fix: update content to take in either a string, float or int --- contentful/resource_contentful_entry.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/contentful/resource_contentful_entry.go b/contentful/resource_contentful_entry.go index b650657..2879883 100644 --- a/contentful/resource_contentful_entry.go +++ b/contentful/resource_contentful_entry.go @@ -50,8 +50,16 @@ func resourceContentfulEntry() *schema.Resource { Required: true, }, "content": { - Type: schema.TypeString, + Type: schema.TypeList, Required: true, + Elem: &schema.Schema{ + Type: schema.TypeList, + Elem: schema.AnyOf( + &schema.Schema{Type: schema.TypeString}, + &schema.Schema{Type: schema.TypeFloat}, + &schema.Schema{Type: schema.TypeInt}, + ), + }, }, "locale": { Type: schema.TypeString, From 045cde3f823815310896cd366dbbf823f9f898ed Mon Sep 17 00:00:00 2001 From: Nicholas Ting Date: Fri, 15 Sep 2023 00:32:40 +1000 Subject: [PATCH 7/9] fix: num/integer type --- contentful/resource_contentful_entry.go | 31 +++++++++++-------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/contentful/resource_contentful_entry.go b/contentful/resource_contentful_entry.go index 2879883..b577c8c 100644 --- a/contentful/resource_contentful_entry.go +++ b/contentful/resource_contentful_entry.go @@ -50,21 +50,17 @@ func resourceContentfulEntry() *schema.Resource { Required: true, }, "content": { - Type: schema.TypeList, + Type: schema.TypeString, Required: true, - Elem: &schema.Schema{ - Type: schema.TypeList, - Elem: schema.AnyOf( - &schema.Schema{Type: schema.TypeString}, - &schema.Schema{Type: schema.TypeFloat}, - &schema.Schema{Type: schema.TypeInt}, - ), - }, }, "locale": { Type: schema.TypeString, Required: true, }, + "type": { + Type: schema.TypeString, + Optional: true, + }, }, }, }, @@ -100,18 +96,17 @@ func resourceCreateEntry(ctx context.Context, d *schema.ResourceData, env *conte for i := 0; i < len(rawField); i++ { field := rawField[i].(map[string]interface{}) content := field["content"] + fieldType := field["type"].(string) - // Check the type of content and convert to integer if it's an integer. + // Check the type of content and convert accordingly. var fieldValue interface{} - switch content.(type) { - case int: - fieldValue = content.(int) - case float64: - // Handle float64 as well, in case content is a floating-point number. - fieldValue = int(content.(float64)) + switch fieldType { + case "Number": + fieldValue, _ = strconv.ParseFloat(content.(string), 64) + case "Integer": + fieldValue, _ = strconv.Atoi(content.(string)) default: - // If it's not an integer, assume it's a string. - fieldValue = content.(string) + fieldValue = content } fieldProperties[field["id"].(string)] = map[string]interface{}{} From 20caeb4409330a511e51dd6425d3675f47ea0454 Mon Sep 17 00:00:00 2001 From: Nicholas Ting Date: Fri, 15 Sep 2023 00:41:04 +1000 Subject: [PATCH 8/9] fix: strconv --- contentful/resource_contentful_entry.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contentful/resource_contentful_entry.go b/contentful/resource_contentful_entry.go index b577c8c..3564ed5 100644 --- a/contentful/resource_contentful_entry.go +++ b/contentful/resource_contentful_entry.go @@ -2,7 +2,7 @@ package contentful import ( "context" - + "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" contentful "github.com/kitagry/contentful-go" From 837338c755e68cf204a31899bcd92d7f724eff99 Mon Sep 17 00:00:00 2001 From: Nicholas Ting Date: Fri, 15 Sep 2023 08:57:12 +1000 Subject: [PATCH 9/9] fix: number and integer content type --- contentful/resource_contentful_entry.go | 53 +++++++++++++++++-------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/contentful/resource_contentful_entry.go b/contentful/resource_contentful_entry.go index 3564ed5..61d749d 100644 --- a/contentful/resource_contentful_entry.go +++ b/contentful/resource_contentful_entry.go @@ -2,6 +2,7 @@ package contentful import ( "context" + "fmt" "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -50,17 +51,13 @@ func resourceContentfulEntry() *schema.Resource { Required: true, }, "content": { - Type: schema.TypeString, + Type: schema.TypeString, Required: true, }, "locale": { Type: schema.TypeString, Required: true, }, - "type": { - Type: schema.TypeString, - Optional: true, - }, }, }, }, @@ -95,20 +92,25 @@ func resourceCreateEntry(ctx context.Context, d *schema.ResourceData, env *conte rawField := d.Get("field").([]interface{}) for i := 0; i < len(rawField); i++ { field := rawField[i].(map[string]interface{}) - content := field["content"] - fieldType := field["type"].(string) + content, ok := field["content"].(string) + + if !ok { + fmt.Println("content is not a string") + continue + } - // Check the type of content and convert accordingly. var fieldValue interface{} - switch fieldType { - case "Number": - fieldValue, _ = strconv.ParseFloat(content.(string), 64) - case "Integer": - fieldValue, _ = strconv.Atoi(content.(string)) - default: + if floatValue, err := strconv.ParseFloat(content, 64); err == nil { + // fmt.Printf("%s is a float: %f\n", content, floatValue) + fieldValue = floatValue + } else if intValue, err := strconv.Atoi(content); err == nil { + // fmt.Printf("%s is an integer: %d\n", content, intValue) + fieldValue = intValue + } else { + // fmt.Printf("%s is neither an integer nor a float\n", content) fieldValue = content } - + fieldProperties[field["id"].(string)] = map[string]interface{}{} fieldProperties[field["id"].(string)].(map[string]interface{})[field["locale"].(string)] = fieldValue } @@ -161,8 +163,27 @@ func resourceUpdateEntry(ctx context.Context, d *schema.ResourceData, env *conte rawField := d.Get("field").([]interface{}) for i := 0; i < len(rawField); i++ { field := rawField[i].(map[string]interface{}) + content, ok := field["content"].(string) + + if !ok { + fmt.Println("Content is not a string") + continue + } + + var fieldValue interface{} + if floatValue, err := strconv.ParseFloat(content, 64); err == nil { + // fmt.Printf("%s is a float: %f\n", content, floatValue) + fieldValue = floatValue + } else if intValue, err := strconv.Atoi(content); err == nil { + // fmt.Printf("%s is an integer: %d\n", content, intValue) + fieldValue = intValue + } else { + // fmt.Printf("%s is neither an integer nor a float\n", content) + fieldValue = content + } + fieldProperties[field["id"].(string)] = map[string]interface{}{} - fieldProperties[field["id"].(string)].(map[string]interface{})[field["locale"].(string)] = field["content"].(string) + fieldProperties[field["id"].(string)].(map[string]interface{})[field["locale"].(string)] = fieldValue } entry.Fields = fieldProperties