Cloud Terraform-错误:[调试]在输入字节1处创建SSH密钥非法base64数据

Cloud Terraform-错误:[调试]在输入字节1处创建SSH密钥非法base64数据,cloud,websphere,terraform,Cloud,Websphere,Terraform,我试图在IBM cloud上运行以下代码以提供不同的资源,所有这些资源都已创建,但VSI/VM实例的公钥存在问题,但不确定发生了什么,下面是代码测试。tf: # Configure the IBM Cloud Provider provider "ibm" { ibmcloud_api_key = "${var.ibmcloud_api_key}" generation = 2 region

我试图在IBM cloud上运行以下代码以提供不同的资源,所有这些资源都已创建,但VSI/VM实例的公钥存在问题,但不确定发生了什么,下面是代码测试。tf:

# Configure the IBM Cloud Provider
provider "ibm" {
  ibmcloud_api_key      = "${var.ibmcloud_api_key}"
  generation            = 2
  region                = "us-south"

}



###################Reources###################

#VPC
resource "ibm_is_vpc" "vpc1" {
  name                  = "vpc1"
}


#Subnet for the VPC
resource "ibm_is_subnet" "subnet1" {
  name            = "subnet1"
  vpc             = ibm_is_vpc.vpc1.id
  zone            = "${var.zone1}"
  ipv4_cidr_block = "10.240.0.0/24"
}


#Second Subnet for bastion VSI
resource "ibm_is_subnet" "subnet2" {
  name            = "subnet2"
  vpc             = ibm_is_vpc.vpc1.id
  zone            = "${var.zone1}"
  ipv4_cidr_block = "10.240.1.0/24"
  public_gateway = "${ibm_is_public_gateway.gateway.id}"
}


#Public Gateway
resource "ibm_is_public_gateway" "gateway" {
  name = "gateway"
  vpc  = ibm_is_vpc.vpc1.id
  zone = "${var.zone1}"
}


#data SSH
resource "ibm_is_ssh_key" "ssh_public_key" {
    name = "testssh"
    public_key = var.ssh_public_key
}


#VSI

resource "ibm_is_instance" "vm1" {
  name              = "vm1"
  image             = "${var.image}"
  profile           = "${var.profile}"
  zone              = "${var.zone1}"
  keys              = [ibm_is_ssh_key.ssh_public_key.id]
  vpc               = ibm_is_vpc.vpc1.id

  primary_network_interface {
    subnet          = ibm_is_subnet.subnet2.id
  }

  network_interfaces {
    name            = "eth1"
    subnet          = ibm_is_subnet.subnet2.id

  }

  }
#variables

#API Key top connect to my IBM Cloud
variable "ibmcloud_api_key" {
    default = "9lsRdBjb70PlwxxxxxxxxxxxxxxxxxxxLdf6"
}


##What zone I want to use
#IBMcloud regions would help to get the regions/zones
variable "zone1" {
    default = "us-south-1"

}


#SVSI image template
#ibmcloud is image command
variable "image" {
    default = "6aec77ca-ab4a-459e-81dc-6e5ec9f99d4a" #centos minimal

}


#SSH key for the VMs/VSIs for provisioning
variable "ssh_public_key" {
    default = "C:/Users/User.Name/ibmkey.pub"

}


#VSI config
#ibmcloud is instance-profiles command
variable "profile" {
    default = "bc1-2x8" #2CPUs and 8GB of RAM

}
Error: [DEBUG] Create SSH Key illegal base64 data at input byte 1
{
    "StatusCode": 400,
    "Headers": {
        "Cache-Control": [
            "max-age=0, no-cache, no-store, must-revalidate"
        ],
        "Cf-Cache-Status": [
            "DYNAMIC"
        ],
        "Cf-Ray": [
            "5b8ab320e9c4b959-MIA"
        ],
        "Cf-Request-Id": [
            "042a8e48910000b959aa8fe200000001"
        ],
        "Connection": [
            "keep-alive"
        ],
        "Content-Length": [
            "187"
        ],
        "Content-Security-Policy": [
            "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://ssl.google-analytics.com https://assets.zendesk.com https://connect.facebook.net; img-src 'self' https://ssl.google-analytics.com https://s-static.ak.facebook.com https://assets.zendesk.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://assets.zendesk.com; font-src 'self' https://themes.googleusercontent.com; frame-src https://assets.zendesk.com https://www.facebook.com https://s-static.ak.facebook.com https://tautt.zendesk.com; object-src 'none'"
        ],
        "Content-Type": [
            "application/json; charset=utf-8"
        ],
        "Date": [
            "Sun, 26 Jul 2020 02:30:37 GMT"
        ],
        "Expect-Ct": [
            "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""
        ],
        "Expires": [
            "-1"
        ],
        "Pragma": [
            "no-cache"
        ],
        "Server": [
            "cloudflare"
        ],
        "Set-Cookie": [
            "__cfduid=dab8eaaa41dc1d2e24658e3191d0e3d881595730636; expires=Tue, 25-Aug-20 02:30:36 GMT; path=/; domain=.iaas.cloud.ibm.com; HttpOnly; SameSite=Lax; Secure"
        ],
        "Strict-Transport-Security": [
            "max-age=31536000; includeSubDomains"
        ],
        "Vary": [
            "Accept-Encoding"
        ],
        "X-Content-Type-Options": [
            "nosniff"
        ],
        "X-Request-Id": [
            "7ff3ada5-02e8-4fb2-a1f2-5fa9ca4da415"
        ],
        "X-Trace-Id": [
            "7108b437f9d18820"
        ],
        "X-Xss-Protection": [
            "1; mode=block"
        ]
    },
    "Result": {
        "errors": [
            {
                "code": "key_parse_failure",
                "message": "illegal base64 data at input byte 1",
                "target": {
                    "name": "key.public_key",
                    "type": "field"
                }
            }
        ],
        "trace": "7ff3ada5-02e8-4fb2-a1f2-5fa9ca4da415"
    },
    "RawResult": null
}


  on test1.tf line 51, in resource "ibm_is_ssh_key" "ssh_public_key":
  51: resource "ibm_is_ssh_key" "ssh_public_key" {
这是变量文件variables.tf:

# Configure the IBM Cloud Provider
provider "ibm" {
  ibmcloud_api_key      = "${var.ibmcloud_api_key}"
  generation            = 2
  region                = "us-south"

}



###################Reources###################

#VPC
resource "ibm_is_vpc" "vpc1" {
  name                  = "vpc1"
}


#Subnet for the VPC
resource "ibm_is_subnet" "subnet1" {
  name            = "subnet1"
  vpc             = ibm_is_vpc.vpc1.id
  zone            = "${var.zone1}"
  ipv4_cidr_block = "10.240.0.0/24"
}


#Second Subnet for bastion VSI
resource "ibm_is_subnet" "subnet2" {
  name            = "subnet2"
  vpc             = ibm_is_vpc.vpc1.id
  zone            = "${var.zone1}"
  ipv4_cidr_block = "10.240.1.0/24"
  public_gateway = "${ibm_is_public_gateway.gateway.id}"
}


#Public Gateway
resource "ibm_is_public_gateway" "gateway" {
  name = "gateway"
  vpc  = ibm_is_vpc.vpc1.id
  zone = "${var.zone1}"
}


#data SSH
resource "ibm_is_ssh_key" "ssh_public_key" {
    name = "testssh"
    public_key = var.ssh_public_key
}


#VSI

resource "ibm_is_instance" "vm1" {
  name              = "vm1"
  image             = "${var.image}"
  profile           = "${var.profile}"
  zone              = "${var.zone1}"
  keys              = [ibm_is_ssh_key.ssh_public_key.id]
  vpc               = ibm_is_vpc.vpc1.id

  primary_network_interface {
    subnet          = ibm_is_subnet.subnet2.id
  }

  network_interfaces {
    name            = "eth1"
    subnet          = ibm_is_subnet.subnet2.id

  }

  }
#variables

#API Key top connect to my IBM Cloud
variable "ibmcloud_api_key" {
    default = "9lsRdBjb70PlwxxxxxxxxxxxxxxxxxxxLdf6"
}


##What zone I want to use
#IBMcloud regions would help to get the regions/zones
variable "zone1" {
    default = "us-south-1"

}


#SVSI image template
#ibmcloud is image command
variable "image" {
    default = "6aec77ca-ab4a-459e-81dc-6e5ec9f99d4a" #centos minimal

}


#SSH key for the VMs/VSIs for provisioning
variable "ssh_public_key" {
    default = "C:/Users/User.Name/ibmkey.pub"

}


#VSI config
#ibmcloud is instance-profiles command
variable "profile" {
    default = "bc1-2x8" #2CPUs and 8GB of RAM

}
Error: [DEBUG] Create SSH Key illegal base64 data at input byte 1
{
    "StatusCode": 400,
    "Headers": {
        "Cache-Control": [
            "max-age=0, no-cache, no-store, must-revalidate"
        ],
        "Cf-Cache-Status": [
            "DYNAMIC"
        ],
        "Cf-Ray": [
            "5b8ab320e9c4b959-MIA"
        ],
        "Cf-Request-Id": [
            "042a8e48910000b959aa8fe200000001"
        ],
        "Connection": [
            "keep-alive"
        ],
        "Content-Length": [
            "187"
        ],
        "Content-Security-Policy": [
            "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://ssl.google-analytics.com https://assets.zendesk.com https://connect.facebook.net; img-src 'self' https://ssl.google-analytics.com https://s-static.ak.facebook.com https://assets.zendesk.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://assets.zendesk.com; font-src 'self' https://themes.googleusercontent.com; frame-src https://assets.zendesk.com https://www.facebook.com https://s-static.ak.facebook.com https://tautt.zendesk.com; object-src 'none'"
        ],
        "Content-Type": [
            "application/json; charset=utf-8"
        ],
        "Date": [
            "Sun, 26 Jul 2020 02:30:37 GMT"
        ],
        "Expect-Ct": [
            "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""
        ],
        "Expires": [
            "-1"
        ],
        "Pragma": [
            "no-cache"
        ],
        "Server": [
            "cloudflare"
        ],
        "Set-Cookie": [
            "__cfduid=dab8eaaa41dc1d2e24658e3191d0e3d881595730636; expires=Tue, 25-Aug-20 02:30:36 GMT; path=/; domain=.iaas.cloud.ibm.com; HttpOnly; SameSite=Lax; Secure"
        ],
        "Strict-Transport-Security": [
            "max-age=31536000; includeSubDomains"
        ],
        "Vary": [
            "Accept-Encoding"
        ],
        "X-Content-Type-Options": [
            "nosniff"
        ],
        "X-Request-Id": [
            "7ff3ada5-02e8-4fb2-a1f2-5fa9ca4da415"
        ],
        "X-Trace-Id": [
            "7108b437f9d18820"
        ],
        "X-Xss-Protection": [
            "1; mode=block"
        ]
    },
    "Result": {
        "errors": [
            {
                "code": "key_parse_failure",
                "message": "illegal base64 data at input byte 1",
                "target": {
                    "name": "key.public_key",
                    "type": "field"
                }
            }
        ],
        "trace": "7ff3ada5-02e8-4fb2-a1f2-5fa9ca4da415"
    },
    "RawResult": null
}


  on test1.tf line 51, in resource "ibm_is_ssh_key" "ssh_public_key":
  51: resource "ibm_is_ssh_key" "ssh_public_key" {
以下是运行应用后的错误输出:

# Configure the IBM Cloud Provider
provider "ibm" {
  ibmcloud_api_key      = "${var.ibmcloud_api_key}"
  generation            = 2
  region                = "us-south"

}



###################Reources###################

#VPC
resource "ibm_is_vpc" "vpc1" {
  name                  = "vpc1"
}


#Subnet for the VPC
resource "ibm_is_subnet" "subnet1" {
  name            = "subnet1"
  vpc             = ibm_is_vpc.vpc1.id
  zone            = "${var.zone1}"
  ipv4_cidr_block = "10.240.0.0/24"
}


#Second Subnet for bastion VSI
resource "ibm_is_subnet" "subnet2" {
  name            = "subnet2"
  vpc             = ibm_is_vpc.vpc1.id
  zone            = "${var.zone1}"
  ipv4_cidr_block = "10.240.1.0/24"
  public_gateway = "${ibm_is_public_gateway.gateway.id}"
}


#Public Gateway
resource "ibm_is_public_gateway" "gateway" {
  name = "gateway"
  vpc  = ibm_is_vpc.vpc1.id
  zone = "${var.zone1}"
}


#data SSH
resource "ibm_is_ssh_key" "ssh_public_key" {
    name = "testssh"
    public_key = var.ssh_public_key
}


#VSI

resource "ibm_is_instance" "vm1" {
  name              = "vm1"
  image             = "${var.image}"
  profile           = "${var.profile}"
  zone              = "${var.zone1}"
  keys              = [ibm_is_ssh_key.ssh_public_key.id]
  vpc               = ibm_is_vpc.vpc1.id

  primary_network_interface {
    subnet          = ibm_is_subnet.subnet2.id
  }

  network_interfaces {
    name            = "eth1"
    subnet          = ibm_is_subnet.subnet2.id

  }

  }
#variables

#API Key top connect to my IBM Cloud
variable "ibmcloud_api_key" {
    default = "9lsRdBjb70PlwxxxxxxxxxxxxxxxxxxxLdf6"
}


##What zone I want to use
#IBMcloud regions would help to get the regions/zones
variable "zone1" {
    default = "us-south-1"

}


#SVSI image template
#ibmcloud is image command
variable "image" {
    default = "6aec77ca-ab4a-459e-81dc-6e5ec9f99d4a" #centos minimal

}


#SSH key for the VMs/VSIs for provisioning
variable "ssh_public_key" {
    default = "C:/Users/User.Name/ibmkey.pub"

}


#VSI config
#ibmcloud is instance-profiles command
variable "profile" {
    default = "bc1-2x8" #2CPUs and 8GB of RAM

}
Error: [DEBUG] Create SSH Key illegal base64 data at input byte 1
{
    "StatusCode": 400,
    "Headers": {
        "Cache-Control": [
            "max-age=0, no-cache, no-store, must-revalidate"
        ],
        "Cf-Cache-Status": [
            "DYNAMIC"
        ],
        "Cf-Ray": [
            "5b8ab320e9c4b959-MIA"
        ],
        "Cf-Request-Id": [
            "042a8e48910000b959aa8fe200000001"
        ],
        "Connection": [
            "keep-alive"
        ],
        "Content-Length": [
            "187"
        ],
        "Content-Security-Policy": [
            "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://ssl.google-analytics.com https://assets.zendesk.com https://connect.facebook.net; img-src 'self' https://ssl.google-analytics.com https://s-static.ak.facebook.com https://assets.zendesk.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://assets.zendesk.com; font-src 'self' https://themes.googleusercontent.com; frame-src https://assets.zendesk.com https://www.facebook.com https://s-static.ak.facebook.com https://tautt.zendesk.com; object-src 'none'"
        ],
        "Content-Type": [
            "application/json; charset=utf-8"
        ],
        "Date": [
            "Sun, 26 Jul 2020 02:30:37 GMT"
        ],
        "Expect-Ct": [
            "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""
        ],
        "Expires": [
            "-1"
        ],
        "Pragma": [
            "no-cache"
        ],
        "Server": [
            "cloudflare"
        ],
        "Set-Cookie": [
            "__cfduid=dab8eaaa41dc1d2e24658e3191d0e3d881595730636; expires=Tue, 25-Aug-20 02:30:36 GMT; path=/; domain=.iaas.cloud.ibm.com; HttpOnly; SameSite=Lax; Secure"
        ],
        "Strict-Transport-Security": [
            "max-age=31536000; includeSubDomains"
        ],
        "Vary": [
            "Accept-Encoding"
        ],
        "X-Content-Type-Options": [
            "nosniff"
        ],
        "X-Request-Id": [
            "7ff3ada5-02e8-4fb2-a1f2-5fa9ca4da415"
        ],
        "X-Trace-Id": [
            "7108b437f9d18820"
        ],
        "X-Xss-Protection": [
            "1; mode=block"
        ]
    },
    "Result": {
        "errors": [
            {
                "code": "key_parse_failure",
                "message": "illegal base64 data at input byte 1",
                "target": {
                    "name": "key.public_key",
                    "type": "field"
                }
            }
        ],
        "trace": "7ff3ada5-02e8-4fb2-a1f2-5fa9ca4da415"
    },
    "RawResult": null
}


  on test1.tf line 51, in resource "ibm_is_ssh_key" "ssh_public_key":
  51: resource "ibm_is_ssh_key" "ssh_public_key" {

有什么想法吗?

我认为这里发生的是,您将SSH公钥指定为文件名,而不是实际的公钥定义,因此提供程序将文本字符串
C:/Users/User.Name/ibmkey.pub
发送为您的密钥,而不是该文件的内容

我不太熟悉这个提供者,但我认为它希望您已经阅读了该文件,并将其内容作为
ibm\u的
public\u key
参数is\u ssh\u key
传递

如何在这里继续的两个主要选项是,在设置
ssh\u public\u key
变量时传递文件内容,使调用者负责首先将文件读入内存,或者更改模块将给定文件读入内存本身:

resource "ibm_is_ssh_key" "ssh_public_key" {
    name       = "testssh"
    public_key = file(var.ssh_public_key)
}

,此错误消息的大部分是直接从远程API返回的,因此,如果读取文件也不起作用,您可能需要查阅此
POST/keys
API操作的文档,以了解其
key.public\u key
参数的格式,然后在Terraform配置中匹配该格式。

我认为这里发生的事情是,您将SSH公钥指定为文件名,而不是实际的公钥定义,因此提供程序将文本字符串
C:/Users/User.Name/ibmkey.pub
发送为您的密钥,而不是该文件的内容

我不太熟悉这个提供者,但我认为它希望您已经阅读了该文件,并将其内容作为
ibm\u的
public\u key
参数is\u ssh\u key
传递

如何在这里继续的两个主要选项是,在设置
ssh\u public\u key
变量时传递文件内容,使调用者负责首先将文件读入内存,或者更改模块将给定文件读入内存本身:

resource "ibm_is_ssh_key" "ssh_public_key" {
    name       = "testssh"
    public_key = file(var.ssh_public_key)
}

,此错误消息的大部分是直接从远程API返回的,因此,如果读取文件也不起作用,您可能需要查阅此
POST/keys
API操作的文档,以了解其
key.public\u key
参数的格式,然后在Terraform配置中匹配该格式。

我一直在谷歌搜索,但找不到任何错误代码的引用。我一直在谷歌搜索,但找不到任何错误代码的引用。我确实将文件内容直接粘贴到参数中,它起了作用,因此是的,我需要“file()”以正确打开文件。谢谢你,马丁!我确实将文件contento直接粘贴到了参数中,它起了作用,所以是的,我需要“file()”来正确打开文件。谢谢你,马丁!