mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-03 01:01:06 +00:00
Add hostname field to compute_instance (#2952)
Signed-off-by: Modular Magician <magic-modules@google.com>
This commit is contained in:
parent
60264e386c
commit
ced540ceca
@ -537,6 +537,12 @@ func resourceComputeInstance() *schema.Resource {
|
|||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"hostname": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
CustomizeDiff: customdiff.All(
|
CustomizeDiff: customdiff.All(
|
||||||
customdiff.If(
|
customdiff.If(
|
||||||
@ -674,6 +680,7 @@ func expandComputeInstance(project string, zone *compute.Zone, d *schema.Resourc
|
|||||||
MinCpuPlatform: d.Get("min_cpu_platform").(string),
|
MinCpuPlatform: d.Get("min_cpu_platform").(string),
|
||||||
Scheduling: scheduling,
|
Scheduling: scheduling,
|
||||||
DeletionProtection: d.Get("deletion_protection").(bool),
|
DeletionProtection: d.Get("deletion_protection").(bool),
|
||||||
|
Hostname: d.Get("hostname").(string),
|
||||||
ForceSendFields: []string{"CanIpForward", "DeletionProtection"},
|
ForceSendFields: []string{"CanIpForward", "DeletionProtection"},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@ -892,6 +899,7 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
|
|||||||
d.Set("project", project)
|
d.Set("project", project)
|
||||||
d.Set("zone", GetResourceNameFromSelfLink(instance.Zone))
|
d.Set("zone", GetResourceNameFromSelfLink(instance.Zone))
|
||||||
d.Set("name", instance.Name)
|
d.Set("name", instance.Name)
|
||||||
|
d.Set("hostname", instance.Hostname)
|
||||||
d.SetId(instance.Name)
|
d.SetId(instance.Name)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -1043,6 +1043,26 @@ func TestAccComputeInstance_secondaryAliasIpRange(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccComputeInstance_hostname(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccComputeInstance_hostname(instanceName),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
resource.TestCheckResourceAttrSet("google_compute_instance.foobar", "hostname"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
computeInstanceImportStep("us-central1-a", instanceName, []string{}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckComputeInstanceUpdateMachineType(n string) resource.TestCheckFunc {
|
func testAccCheckComputeInstanceUpdateMachineType(n string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
@ -2908,6 +2928,33 @@ resource "google_compute_instance" "foobar" {
|
|||||||
}`, network, subnet, instance)
|
}`, network, subnet, instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccComputeInstance_hostname(instance string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
data "google_compute_image" "my_image" {
|
||||||
|
family = "debian-9"
|
||||||
|
project = "debian-cloud"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_instance" "foobar" {
|
||||||
|
name = "%s"
|
||||||
|
machine_type = "n1-standard-1"
|
||||||
|
zone = "us-central1-a"
|
||||||
|
can_ip_forward = false
|
||||||
|
|
||||||
|
boot_disk {
|
||||||
|
initialize_params{
|
||||||
|
image = "${data.google_compute_image.my_image.self_link}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
network_interface {
|
||||||
|
network = "default"
|
||||||
|
}
|
||||||
|
|
||||||
|
hostname = "%s.test"
|
||||||
|
}`, instance, instance)
|
||||||
|
}
|
||||||
|
|
||||||
// Set fields that require stopping the instance: machine_type, min_cpu_platform, and service_account
|
// Set fields that require stopping the instance: machine_type, min_cpu_platform, and service_account
|
||||||
func testAccComputeInstance_stopInstanceToUpdate(instance string) string {
|
func testAccComputeInstance_stopInstanceToUpdate(instance string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
|
@ -94,6 +94,10 @@ The following arguments are supported:
|
|||||||
* `deletion_protection` - (Optional) Enable deletion protection on this instance. Defaults to false.
|
* `deletion_protection` - (Optional) Enable deletion protection on this instance. Defaults to false.
|
||||||
**Note:** you must disable deletion protection before removing the resource (e.g., via `terraform destroy`), or the instance cannot be deleted and the Terraform run will not complete successfully.
|
**Note:** you must disable deletion protection before removing the resource (e.g., via `terraform destroy`), or the instance cannot be deleted and the Terraform run will not complete successfully.
|
||||||
|
|
||||||
|
* `hostname` - (Optional) A custom hostname for the instance. Must be a fully qualified DNS name and RFC-1035-valid.
|
||||||
|
Valid format is a series of labels 1-63 characters long matching the regular expression `[a-z]([-a-z0-9]*[a-z0-9])`, concatenated with periods.
|
||||||
|
The entire hostname must not exceed 253 characters. Changing this forces a new resource to be created.
|
||||||
|
|
||||||
* `guest_accelerator` - (Optional) List of the type and count of accelerator cards attached to the instance. Structure documented below.
|
* `guest_accelerator` - (Optional) List of the type and count of accelerator cards attached to the instance. Structure documented below.
|
||||||
**Note:** GPU accelerators can only be used with [`on_host_maintenance`](#on_host_maintenance) option set to TERMINATE.
|
**Note:** GPU accelerators can only be used with [`on_host_maintenance`](#on_host_maintenance) option set to TERMINATE.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user