GoogleCloudPlatform / GoogleCloudPlatform/konlet

Probably undocumented way to use gce terraform module with compute instance and disk

Open
#69 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
88
Forks
24
PR merge metrics
No merged PRs in 30d

Description

In konlet's volumes, in line https://github.com/GoogleCloudPlatform/konlet/blob/master/gce-containers-startup/volumes/volumes.go#L387 you populate the map using the **device name**.

Yet, in line https://github.com/GoogleCloudPlatform/konlet/blob/master/gce-containers-startup/volumes/volumes.go#L322 you try to access the same map using the **volume's pd name**.

This is either a weird bug or an undocumented feature, because I could not find anything in the official docs about how to make a GCE instance work with an attached disk.

My (now working) setup consists of the following:

gce instance metadata

```
module "gce-container-foo" {
source = "github.com/terraform-google-modules/terraform-google-container-vm"

container = {
image = "foo"

volumeMounts = [
{
name = "foo-data"
mountPath = "/opt/foo"
}
]
}

volumes = [
{
name = "foo-data"
gcePersistentDisk = {
pdName = google_compute_disk.foo-data.name
fsType = "ext4"
}
}
]
}
```

persistent disk

```
resource "google_compute_disk" "foo-data" {
name = "foo-data"
type = "pd-standard"
zone = var.primary_zone
size = "10"
}
```

compute instance

```
resource "google_compute_instance" "foo" {
name = "foo"
machine_type = "g1-small"
zone = var.primary_zone
deletion_protection = false
allow_stopping_for_update = true

boot_disk {
initialize_params {
image = module.gce-container-sonarqube.source_image
size = "10"
type = "pd-standard"
}
}

attached_disk {
source = google_compute_disk.foo-data.self_link
device_name = google_compute_disk.foo-data.name
}

network_interface {
...
}

metadata = {
gce-container-declaration = module.gce-container-foo.metadata_value
google-logging-enabled = "true"
google-monitoring-enabled = "true"
}

labels = {
container-vm = module.gce-container-foo.vm_container_label
}

service_account {
scopes = ["cloud-platform"]
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.