Terraform AWS API Gateway aws_api_gateway_model问题

huangapple go评论57阅读模式
英文:

Terraform AWS API Gateway aws_api_gateway_model issue

问题

Here is the translation of the code snippet you provided:

我是 Terraform 的新手,尝试通过 Terraform 创建 API 网关。

这是我的代码:

resource "aws_api_gateway_rest_api" "demo_services_apig" {
  name        = "demo-services-apigateway-${var.environment}"
  description = "Demo service APIs to handle Snow events and User Authentication"
  api_key_source = "HEADER"
  endpoint_configuration {
    types = ["REGIONAL"]
  }
}

resource "aws_api_gateway_model" "demo_services_apig_model" {
  rest_api_id = aws_api_gateway_rest_api.demo_services_apig.id
  name        = "UserOauthAPIResponseModel"
  description = "a JSON schema"
  content_type = "application/json"

  schema = jsonencode({
    type = "${file("api_gateway/json_files/oauth_response.json")}"
  })
}

这是位于 api_gateway/json_files/* 下的 schema JSON,在控制台配置时运行良好。

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "UserOAuthUserConfig",
    "type": "object",
    "properties": {
        "Role": {
            "type": "string"
        },
        "Policy": {
            "type": "string"
        },
        "HomeDirectory": {
            "type": "string"
        },
        "PublicKeys": {
            "type": "array",
            "items": {
                "type": "string"
            }
        }
    }
}

我在 Terraform 中遇到以下错误,不知道问题出在哪里:

│ 错误:创建 API Gateway 模型(UserOauthAPIResponseModel)时出错:BadRequestException:指定了无效的模型:验证结果:警告:[],错误:[指定了无效的模型模式]
│ 
│ 位于模块.api_gateway.aws_api_gateway_model.demo_services_apig_model,
│ 在 api_gateway/main.tf 的第 15 行,资源 "aws_api_gateway_model" "demo_services_apig_model":
│ 15: resource "aws_api_gateway_model" "demo_services_apig_model" {

I have provided the translated code snippet as requested. If you have any further questions or need assistance with the code, please feel free to ask.

英文:

I am new to terraform and trying to create API Gateway via terraform.

Here is my code

resource "aws_api_gateway_rest_api" "demo_services_apig" {
  name = "demo-services-apigateway-${var.environment}"
  description = "Demo service APIs to handle Snow events and User Authentication"
  api_key_source = "HEADER"
  endpoint_configuration {
    types = ["REGIONAL"]
  }
}


resource "aws_api_gateway_model" "demo_services_apig_model" {
  rest_api_id = aws_api_gateway_rest_api.demo_services_apig.id
  name = "UserOauthAPIResponseModel"
  description = "a JSON schema"
  content_type = "application/json"

  schema = jsonencode({
    type = "${file("api_gateway/json_files/oauth_response.json")}"
  })
}

Here is schema JSON under api_gateway/json_files/* which works fine if I configure it from console.

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "UserOAuthUserConfig",
    "type": "object",
    "properties": {
        "Role": {
            "type": "string"
        },
        "Policy": {
            "type": "string"
        },
        "HomeDirectory": {
            "type": "string"
        },
        "PublicKeys": {
            "type": "array",
            "items": {
                "type": "string"
            }
        }
    }
}

I am getting below error in Terraform and not able to figure out what's wrong here.

│ Error: creating API Gateway Model (UserOauthAPIResponseModel): BadRequestException: Invalid model specified: Validation Result: warnings : [], errors : [Invalid model schema specified]
│ 
│   with module.api_gateway.aws_api_gateway_model.demo_services_apig_model,
│   on api_gateway/main.tf line 15, in resource "aws_api_gateway_model" "demo_services_apig_model":
│   15: resource "aws_api_gateway_model" "demo_services_apig_model" {

答案1

得分: 0

以下是您要翻译的内容:

"Created model manually in console and use get-model CLI command to check format. use same format in terraform.

resource "aws_api_gateway_model" "demo_services_apig_model" {
rest_api_id = aws_api_gateway_rest_api.demo_services_apig.id
name = "UserOauthAPIResponseModel"
description = "a JSON schema"
content_type = "application/json"
schema = "{"$schema":"http://json-schema.org/draft-04/schema#","title":"UserUserConfig","type":"object","properties":{"Role":{"type":"string"},"Policy":{"type":"string"},"HomeDirectory":{"type":"string"},"PublicKeys":{"type":"array","items":{"type":"string"}}}}"
}"

英文:

Created model manually in console and use get-model CLI command to check format. use same format in terraform.

resource "aws_api_gateway_model" "demo_services_apig_model" {
  rest_api_id = aws_api_gateway_rest_api.demo_services_apig.id
  name = "UserOauthAPIResponseModel"
  description = "a JSON schema"
  content_type = "application/json"
  schema = "{\"$schema\":\"http://json-schema.org/draft-04/schema#\",\"title\":\"UserUserConfig\",\"type\":\"object\",\"properties\":{\"Role\":{\"type\":\"string\"},\"Policy\":{\"type\":\"string\"},\"HomeDirectory\":{\"type\":\"string\"},\"PublicKeys\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}}}"
}

huangapple
  • 本文由 发表于 2023年4月20日 02:31:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76057794.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定