Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable google_compute_instance_group to accept instances id #3621

Merged
merged 1 commit into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions third_party/terraform/resources/resource_compute_instance_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,19 @@ func resourceComputeInstanceGroupCreate(d *schema.ResourceData, meta interface{}
}

if v, ok := d.GetOk("instances"); ok {
instanceUrls := convertStringArr(v.(*schema.Set).List())
if !validInstanceURLs(instanceUrls) {
return fmt.Errorf("Error invalid instance URLs: %v", instanceUrls)
tmpUrls := convertStringArr(v.(*schema.Set).List())

var instanceUrls []string
for _, v := range tmpUrls {
if strings.HasPrefix(v, "https://") {
instanceUrls = append(instanceUrls, v)
} else {
url, err := replaceVars(d, config, "{{ComputeBasePath}}"+v)
if err != nil {
return err
}
instanceUrls = append(instanceUrls, url)
}
}

addInstanceReq := &compute.InstanceGroupsAddInstancesRequest{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ resource "google_compute_instance_group" "basic" {
description = "Terraform test instance group"
name = "%s"
zone = "%s"
instances = [google_compute_instance.ig_instance.self_link]
instances = [google_compute_instance.ig_instance.id]
named_port {
name = "http"
port = "8080"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ resource "google_compute_instance_group" "webservers" {
description = "Terraform test instance group"

instances = [
google_compute_instance.test.self_link,
google_compute_instance.test2.self_link,
google_compute_instance.test.id,
google_compute_instance.test2.id,
]

named_port {
Expand All @@ -63,7 +63,7 @@ as shown in this example to avoid this type of error.
resource "google_compute_instance_group" "staging_group" {
name = "staging-instance-group"
zone = "us-central1-c"
instances = [google_compute_instance.staging_vm.self_link]
instances = [google_compute_instance.staging_vm.id]
named_port {
name = "http"
port = "8080"
Expand Down Expand Up @@ -136,7 +136,7 @@ The following arguments are supported:
group.

* `instances` - (Optional) List of instances in the group. They should be given
as self_link URLs. When adding instances they must all be in the same
as either self_link or id. When adding instances they must all be in the same
network and zone as the instance group.

* `named_port` - (Optional) The named port configuration. See the section below
Expand Down