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 diff --git a/contentful/resource_contentful_entry.go b/contentful/resource_contentful_entry.go index 9fe3fa1..61d749d 100644 --- a/contentful/resource_contentful_entry.go +++ b/contentful/resource_contentful_entry.go @@ -2,7 +2,8 @@ package contentful import ( "context" - + "fmt" + "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" contentful "github.com/kitagry/contentful-go" @@ -50,7 +51,7 @@ func resourceContentfulEntry() *schema.Resource { Required: true, }, "content": { - Type: schema.TypeString, + Type: schema.TypeString, Required: true, }, "locale": { @@ -91,8 +92,27 @@ 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, 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 := &contentful.Entry{ @@ -143,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