mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-03 08:42:39 +00:00
Deprecate address in compute_instance family, undeprecate network_ip (#2096)
Also remove a duplicate instance test I noticed for ephemeral ips.
This commit is contained in:
parent
33d900537d
commit
41d47ec8bb
|
@ -147,7 +147,8 @@ func expandNetworkInterfaces(d *schema.ResourceData, config *Config) ([]*compute
|
|||
AliasIpRanges: expandAliasIpRanges(data["alias_ip_range"].([]interface{})),
|
||||
}
|
||||
|
||||
// network_ip is deprecated. We want address to win if both are set.
|
||||
// address is deprecated, but address took priority over networkIP before
|
||||
// so it should until it's removed.
|
||||
if data["address"].(string) != "" {
|
||||
ifaces[i].NetworkIP = data["address"].(string)
|
||||
}
|
||||
|
|
|
@ -168,18 +168,18 @@ func resourceComputeInstance() *schema.Resource {
|
|||
},
|
||||
|
||||
"address": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"network_ip": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Computed: true,
|
||||
Deprecated: "Please use address",
|
||||
Deprecated: "Please use network_ip",
|
||||
},
|
||||
|
||||
"network_ip": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"access_config": &schema.Schema{
|
||||
|
|
|
@ -147,11 +147,11 @@ func TestAccComputeInstanceTemplate_networkIP(t *testing.T) {
|
|||
},
|
||||
})
|
||||
}
|
||||
func TestAccComputeInstanceTemplate_address(t *testing.T) {
|
||||
func TestAccComputeInstanceTemplate_networkIPAddress(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var instanceTemplate compute.InstanceTemplate
|
||||
address := "10.128.0.2"
|
||||
ipAddress := "10.128.0.2"
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -159,13 +159,13 @@ func TestAccComputeInstanceTemplate_address(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstanceTemplate_address(address),
|
||||
Config: testAccComputeInstanceTemplate_networkIPAddress(ipAddress),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceTemplateExists(
|
||||
"google_compute_instance_template.foobar", &instanceTemplate),
|
||||
testAccCheckComputeInstanceTemplateNetwork(&instanceTemplate),
|
||||
testAccCheckComputeInstanceTemplateAddress(
|
||||
"google_compute_instance_template.foobar", address, &instanceTemplate),
|
||||
testAccCheckComputeInstanceTemplateNetworkIPAddress(
|
||||
"google_compute_instance_template.foobar", ipAddress, &instanceTemplate),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
|
@ -648,14 +648,14 @@ func testAccCheckComputeInstanceTemplateNetworkIP(n, networkIP string, instanceT
|
|||
}
|
||||
}
|
||||
|
||||
func testAccCheckComputeInstanceTemplateAddress(n, address string, instanceTemplate *compute.InstanceTemplate) resource.TestCheckFunc {
|
||||
func testAccCheckComputeInstanceTemplateNetworkIPAddress(n, ipAddress string, instanceTemplate *compute.InstanceTemplate) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
ip := instanceTemplate.Properties.NetworkInterfaces[0].NetworkIP
|
||||
err := resource.TestCheckResourceAttr(n, "network_interface.0.network_ip", ip)(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return resource.TestCheckResourceAttr(n, "network_interface.0.network_ip", address)(s)
|
||||
return resource.TestCheckResourceAttr(n, "network_interface.0.network_ip", ipAddress)(s)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -888,7 +888,7 @@ resource "google_compute_instance_template" "foobar" {
|
|||
}`, acctest.RandString(10), networkIP)
|
||||
}
|
||||
|
||||
func testAccComputeInstanceTemplate_address(address string) string {
|
||||
func testAccComputeInstanceTemplate_networkIPAddress(ipAddress string) string {
|
||||
return fmt.Sprintf(`
|
||||
data "google_compute_image" "my_image" {
|
||||
family = "debian-9"
|
||||
|
@ -906,13 +906,13 @@ resource "google_compute_instance_template" "foobar" {
|
|||
|
||||
network_interface {
|
||||
network = "default"
|
||||
address = "%s"
|
||||
network_ip = "%s"
|
||||
}
|
||||
|
||||
metadata {
|
||||
foo = "bar"
|
||||
}
|
||||
}`, acctest.RandString(10), address)
|
||||
}`, acctest.RandString(10), ipAddress)
|
||||
}
|
||||
|
||||
func testAccComputeInstanceTemplate_disks() string {
|
||||
|
|
|
@ -179,7 +179,7 @@ func TestAccComputeInstance_IP(t *testing.T) {
|
|||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
testAccCheckComputeInstanceAccessConfigHasIP(&instance),
|
||||
testAccCheckComputeInstanceAccessConfigHasNatIP(&instance),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -213,7 +213,7 @@ func TestAccComputeInstance_PTRRecord(t *testing.T) {
|
|||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
testAccCheckComputeInstanceAccessConfigHasIP(&instance),
|
||||
testAccCheckComputeInstanceAccessConfigHasNatIP(&instance),
|
||||
),
|
||||
},
|
||||
computeInstanceImportStep("us-central1-a", instanceName, []string{"metadata.baz", "metadata.foo"}),
|
||||
|
@ -221,28 +221,6 @@ func TestAccComputeInstance_PTRRecord(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccComputeInstance_GenerateIP(t *testing.T) {
|
||||
var instance compute.Instance
|
||||
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{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_generateIp(instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
testAccCheckComputeInstanceAccessConfigHasIP(&instance),
|
||||
testAccCheckComputeInstanceHasAssignedIP,
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccComputeInstance_networkTier(t *testing.T) {
|
||||
var instance compute.Instance
|
||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
|
@ -257,8 +235,8 @@ func TestAccComputeInstance_networkTier(t *testing.T) {
|
|||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
testAccCheckComputeInstanceAccessConfigHasIP(&instance),
|
||||
testAccCheckComputeInstanceHasAssignedIP,
|
||||
testAccCheckComputeInstanceAccessConfigHasNatIP(&instance),
|
||||
testAccCheckComputeInstanceHasAssignedNatIP,
|
||||
),
|
||||
},
|
||||
computeInstanceImportStep("us-central1-a", instanceName, []string{}),
|
||||
|
@ -765,7 +743,7 @@ func TestAccComputeInstance_subnet_xpn(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccComputeInstance_address_auto(t *testing.T) {
|
||||
func TestAccComputeInstance_networkIPAuto(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var instance compute.Instance
|
||||
|
@ -777,34 +755,34 @@ func TestAccComputeInstance_address_auto(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_address_auto(instanceName),
|
||||
Config: testAccComputeInstance_networkIPAuto(instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
testAccCheckComputeInstanceHasAnyAddress(&instance),
|
||||
testAccCheckComputeInstanceHasAnyNetworkIP(&instance),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccComputeInstance_address_custom(t *testing.T) {
|
||||
func TestAccComputeInstance_network_ip_custom(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var instance compute.Instance
|
||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
var address = "10.0.200.200"
|
||||
var ipAddress = "10.0.200.200"
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_address_custom(instanceName, address),
|
||||
Config: testAccComputeInstance_network_ip_custom(instanceName, ipAddress),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
testAccCheckComputeInstanceHasAddress(&instance, address),
|
||||
testAccCheckComputeInstanceHasNetworkIP(&instance, ipAddress),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -1192,7 +1170,7 @@ func testAccCheckComputeInstanceAccessConfig(instance *compute.Instance) resourc
|
|||
}
|
||||
}
|
||||
|
||||
func testAccCheckComputeInstanceAccessConfigHasIP(instance *compute.Instance) resource.TestCheckFunc {
|
||||
func testAccCheckComputeInstanceAccessConfigHasNatIP(instance *compute.Instance) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
for _, i := range instance.NetworkInterfaces {
|
||||
for _, c := range i.AccessConfigs {
|
||||
|
@ -1428,11 +1406,11 @@ func testAccCheckComputeInstanceHasSubnet(instance *compute.Instance) resource.T
|
|||
}
|
||||
}
|
||||
|
||||
func testAccCheckComputeInstanceHasAnyAddress(instance *compute.Instance) resource.TestCheckFunc {
|
||||
func testAccCheckComputeInstanceHasAnyNetworkIP(instance *compute.Instance) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
for _, i := range instance.NetworkInterfaces {
|
||||
if i.NetworkIP == "" {
|
||||
return fmt.Errorf("no address")
|
||||
return fmt.Errorf("no network_ip")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1440,11 +1418,11 @@ func testAccCheckComputeInstanceHasAnyAddress(instance *compute.Instance) resour
|
|||
}
|
||||
}
|
||||
|
||||
func testAccCheckComputeInstanceHasAddress(instance *compute.Instance, address string) resource.TestCheckFunc {
|
||||
func testAccCheckComputeInstanceHasNetworkIP(instance *compute.Instance, networkIP string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
for _, i := range instance.NetworkInterfaces {
|
||||
if i.NetworkIP != address {
|
||||
return fmt.Errorf("Wrong address found: expected %v, got %v", address, i.NetworkIP)
|
||||
if i.NetworkIP != networkIP {
|
||||
return fmt.Errorf("Wrong network_ip found: expected %v, got %v", networkIP, i.NetworkIP)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1514,7 +1492,7 @@ func testAccCheckComputeInstanceHasAliasIpRange(instance *compute.Instance, subn
|
|||
}
|
||||
}
|
||||
|
||||
func testAccCheckComputeInstanceHasAssignedIP(s *terraform.State) error {
|
||||
func testAccCheckComputeInstanceHasAssignedNatIP(s *terraform.State) error {
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "google_compute_instance" {
|
||||
continue
|
||||
|
@ -1905,39 +1883,6 @@ resource "google_compute_instance" "foobar" {
|
|||
`, instance, record)
|
||||
}
|
||||
|
||||
func testAccComputeInstance_generateIp(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"
|
||||
tags = ["foo", "bar"]
|
||||
|
||||
boot_disk {
|
||||
initialize_params{
|
||||
image = "${data.google_compute_image.my_image.self_link}"
|
||||
}
|
||||
}
|
||||
|
||||
network_interface {
|
||||
network = "default"
|
||||
access_config {
|
||||
// generate ephemeral IP
|
||||
}
|
||||
}
|
||||
|
||||
metadata {
|
||||
foo = "bar"
|
||||
}
|
||||
}
|
||||
`, instance)
|
||||
}
|
||||
|
||||
func testAccComputeInstance_networkTier(instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
data "google_compute_image" "my_image" {
|
||||
|
@ -2626,7 +2571,7 @@ resource "google_compute_instance" "foobar" {
|
|||
`, projectName, org, billingId, projectName, org, billingId, acctest.RandString(10), acctest.RandString(10), instance)
|
||||
}
|
||||
|
||||
func testAccComputeInstance_address_auto(instance string) string {
|
||||
func testAccComputeInstance_networkIPAuto(instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
data "google_compute_image" "my_image" {
|
||||
family = "debian-9"
|
||||
|
@ -2662,7 +2607,7 @@ resource "google_compute_instance" "foobar" {
|
|||
`, acctest.RandString(10), acctest.RandString(10), instance)
|
||||
}
|
||||
|
||||
func testAccComputeInstance_address_custom(instance, address string) string {
|
||||
func testAccComputeInstance_network_ip_custom(instance, ipAddress string) string {
|
||||
return fmt.Sprintf(`
|
||||
data "google_compute_image" "my_image" {
|
||||
family = "debian-9"
|
||||
|
@ -2691,12 +2636,12 @@ resource "google_compute_instance" "foobar" {
|
|||
|
||||
network_interface {
|
||||
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.name}"
|
||||
address = "%s"
|
||||
network_ip = "%s"
|
||||
access_config { }
|
||||
}
|
||||
|
||||
}
|
||||
`, acctest.RandString(10), acctest.RandString(10), instance, address)
|
||||
`, acctest.RandString(10), acctest.RandString(10), instance, ipAddress)
|
||||
}
|
||||
|
||||
func testAccComputeInstance_private_image_family(disk, family, instance string) string {
|
||||
|
|
|
@ -85,7 +85,11 @@ The following arguments are supported:
|
|||
|
||||
* `cpu_platform` - The CPU platform used by this instance.
|
||||
|
||||
* `network_interface.0.address` - The internal ip address of the instance, either manually or dynamically assigned.
|
||||
* `network_interface.0.address` - (Deprecated) The internal ip address of the instance, either manually or dynamically assigned.
|
||||
This attribute has been deprecated. Use `network_interface.0.network_ip` instead.
|
||||
|
||||
* `network_interface.0.network_ip` - The internal ip address of the instance, either manually or dynamically assigned.
|
||||
|
||||
|
||||
* `network_interface.0.access_config.0.assigned_nat_ip` - If the instance has an access config, either the given external ip (in the `nat_ip` field) or the ephemeral (generated) ip (if you didn't provide one).
|
||||
|
||||
|
@ -144,7 +148,10 @@ The `network_interface` block supports:
|
|||
|
||||
* `subnetwork_project` - The project in which the subnetwork belongs.
|
||||
|
||||
* `address` - The private IP address assigned to the instance.
|
||||
* `address` - (Deprecated) The private IP address assigned to the instance.
|
||||
This attribute has been deprecated. Use `network_interface.network_ip` instead.
|
||||
|
||||
* `network_ip` - The private IP address assigned to the instance.
|
||||
|
||||
* `access_config` - Access configurations, i.e. IPs via which this
|
||||
instance can be accessed via the Internet. Structure documented below.
|
||||
|
|
|
@ -202,7 +202,11 @@ The `network_interface` block supports:
|
|||
defined in the subnetwork self_link. If the `subnetwork` is a name and this
|
||||
field is not provided, the provider project is used.
|
||||
|
||||
* `address` - (Optional) The private IP address to assign to the instance. If
|
||||
* `address` - (Optional, Deprecated) The private IP address to assign to the instance. If
|
||||
empty, the address will be automatically assigned. This attribute has been deprecated.
|
||||
Use `network_interface.network_ip` instead.
|
||||
|
||||
* `network_ip` - (Optional) The private IP address to assign to the instance. If
|
||||
empty, the address will be automatically assigned.
|
||||
|
||||
* `access_config` - (Optional) Access configurations, i.e. IPs via which this
|
||||
|
@ -287,7 +291,10 @@ exported:
|
|||
|
||||
* `cpu_platform` - The CPU platform used by this instance.
|
||||
|
||||
* `network_interface.0.address` - The internal ip address of the instance, either manually or dynamically assigned.
|
||||
* `network_interface.0.address` - (Deprecated) The internal ip address of the instance, either manually or dynamically assigned.
|
||||
This attribute has been deprecated. Use `network_interface.0.network_ip`instead.
|
||||
|
||||
* `network_interface.0.network_ip` - The internal ip address of the instance, either manually or dynamically assigned.
|
||||
|
||||
* `network_interface.0.access_config.0.assigned_nat_ip` - If the instance has an access config, either the given external ip (in the `nat_ip` field) or the ephemeral (generated) ip (if you didn't provide one).
|
||||
|
||||
|
@ -305,7 +312,7 @@ exported:
|
|||
|
||||
## Import
|
||||
|
||||
~> **Note:** The fields `boot_disk.0.disk_entryption_raw` and `attached_disk.*.disk_encryption_key_raw` cannot be imported automatically. The API doesn't return this information. If you are setting one of these fields in your config, you will need to update your state manually after importing the resource.
|
||||
~> **Note:** The fields `boot_disk.0.disk_encryption_raw` and `attached_disk.*.disk_encryption_key_raw` cannot be imported automatically. The API doesn't return this information. If you are setting one of these fields in your config, you will need to update your state manually after importing the resource.
|
||||
|
||||
Instances can be imported using the `project`, `zone` and `name`, e.g.
|
||||
|
||||
|
|
|
@ -286,7 +286,11 @@ The `network_interface` block supports:
|
|||
* `subnetwork_project` - (Optional) The ID of the project in which the subnetwork belongs.
|
||||
If it is not provided, the provider project is used.
|
||||
|
||||
* `address` - (Optional) The private IP address to assign to the instance. If
|
||||
* `address` - (Optional, Deprecated) The private IP address to assign to the instance. If
|
||||
empty, the address will be automatically assigned. This attribute has been deprecated.
|
||||
Use `network_interface.network_ip` instead.
|
||||
|
||||
* `network_ip` - (Optional) The private IP address to assign to the instance. If
|
||||
empty, the address will be automatically assigned.
|
||||
|
||||
* `access_config` - (Optional) Access configurations, i.e. IPs via which this
|
||||
|
|
Loading…
Reference in New Issue
Block a user