使用terraform将spring boot jar上传到gce实例

2021-01-03 19点热度 0人点赞 0条评论

将some-spring-boot.jar复制到gce实例的最佳方法是什么?

我认为这是一项很常见的任务,但是在谷歌上没有找到关于它的文档。

我已经在gcp中生成了服务帐户,并将所有内容保存到gcp-credentials.json中:

{
  "type": "service_account",
  "project_id": "some project",
  "private_key_id": "someid",
  "private_key": "some key",
  "client_email": "xxx@developer.gserviceaccount.com",
  "client_id": "xxxx",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/xxxdeveloper.gserviceaccount.com"
}

以下是我在谷歌搜索了几个小时后所做的:

terraform {
    required_providers {
        google = {
            source = "hashicorp/google"
        }
    }
}

provider "google" {
    version = "3.5.0"
    credentials = file("gcp-credentials.json")
    project = "some project"
    zone = "us-central1-a"
}

resource "google_compute_instance" "vm_instance" {
    name = "my-instance"
    machine_type = "e2-medium"
    #metadata_startup_script = file("startup.sh")

    tags = [
        "http-server",
        "https-server"]

    boot_disk {
        initialize_params {
            image = "some image with jdk"
        }
    }

    network_interface {
        network = "default"
        access_config {}
    }

    provisioner "file" {
        source = "../../../target/my-jar-1.0.0.jar"
        destination = "/tmp/my-jar-1.0.0.jar"

        connection {
            type = "ssh"
            user = "root"
            private_key = file("gcp-credentials.json").private_key
            agent = "false"
        }
    }
}

每当我运行它时

[ERROR] Error: Missing required argument
[ERROR] 
[ERROR]   on main.tf line 43, in resource "google_compute_instance" "vm_instance":
[ERROR]   43:         connection {
[ERROR] 
[ERROR] The argument "host" is required, but no definition was found.

任何帮助都会非常感谢

查看隐藏内容需要支付:¥1
查看

未经允许不得转载!使用terraform将spring boot jar上传到gce实例

本文地址:https://ans.52learn.online/1879

ANS52LEARN

DO BEST