labd / terraform-provider-amplience

Terraform provider for Amplience
https://registry.terraform.io/providers/labd/amplience/latest
Mozilla Public License 2.0
7 stars 4 forks source link

Authorization Required error while creating content-type-schema #20

Closed manojsharmadcx closed 1 year ago

manojsharmadcx commented 1 year ago

Hi There,

I am trying to create a content type schema using the provider. While doing that, I am constantly getting "Error: Authorization required." event when I have configured the client_id, client_secret, hub_id values in the provider. Below is the TF snippet for content type schema creation and the error snapshot. Any help around what might be causing it is much appreciated.

resource "amplience_content_type_schema" "testContent" { body = <<EOL { "$id": "https://tf-amplience-provider.com/testContent", "$schema": "http://json-schema.org/draft-07/schema#", "allOf": [ { "$ref": "http://bigcontent.io/cms/schema/v1/core#/definitions/content" } ], "title": "TestContent", "description": "TestContent", "type": "object", "properties": { "title": { "title": "Title", "allOf": [ { "$ref": "http://bigcontent.io/cms/schema/v1/localization#/definitions/localized-string" } ] }, "color": { "title": "Color", "type": "string", "format": "color" } }, "propertyOrder": [ "title", "color" ], "required": [ "title", "color" ] } EOL schema_id = "https://tf-amplience-provider.com/testContent" validation_level = "CONTENT_TYPE" }

image
korsvanloon commented 1 year ago

IIRC "authorization required" is the generic error you will get from Amplience if anything goes wrong. In other words, it probably has nothing to do with actual authorization.

It might have to do with the EOL syntax. I would advice to put your schemas in separate json files and then reference them like so:

resource "amplience_content_type_schema" "page_link" {
  body             = file("${path.module}/content-type-schemas/schemas/page-link-schema.json")
  schema_id        = "https://amplience.kato-services.net/page-link"
  validation_level = "CONTENT_TYPE"
}
manojsharmadcx commented 1 year ago

Thanks for your response Kors. I changed the snipped to refer to JSON file as suggested, however still getting the same issue. Below is the code snippet and detailed trace logs of "terraform apply" command. Will appreciate if you can have a look and point to any potential issues.

Resource-

resource "amplience_content_type_schema" "featuredproducts" {
  body             = file("testContent.json")
  schema_id        = "https://schema-test.com/featuredproducts"
  validation_level = "CONTENT_TYPE"
}

testContent.json-

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "https://schema-test.com/featuredproducts",
    "title": "Test Product Carousel",
    "description": "Description",
    "allOf": [
        {
            "$ref": "http://bigcontent.io/cms/schema/v1/core#/definitions/content"
        }
    ],

    "type": "object",
    "properties": {
        "name": {
            "title": "CarouselName",
            "type": "string"
        },
        "typecode": {
            "title": "typecode",
            "type": "string",
            "const": "FeaturedProductsCarousel"
        },
        "banners": {
            "type": "object",
            "allOf": [
                {
                    "$ref": "https://schema-test.com/testhsImage"
                }
            ]
        }

    },
    "propertyOrder": ["name","banners"]
}

Error- provider-logs.txt

manojsharmadcx commented 1 year ago

Apparently there was an issue with hub id configured in the provider. It is working now. Thanks for your support!