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

Deprecate address in compute_instance family, undeprecate network_ip #2096

Merged
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
3 changes: 2 additions & 1 deletion google/compute_instance_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
16 changes: 8 additions & 8 deletions google/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
20 changes: 10 additions & 10 deletions google/resource_compute_instance_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,25 @@ 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) },
Providers: testAccProviders,
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{
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
99 changes: 22 additions & 77 deletions google/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestAccComputeInstance_IP(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists(
"google_compute_instance.foobar", &instance),
testAccCheckComputeInstanceAccessConfigHasIP(&instance),
testAccCheckComputeInstanceAccessConfigHasNatIP(&instance),
),
},
},
Expand Down Expand Up @@ -213,36 +213,14 @@ 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"}),
},
})
}

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))
Expand All @@ -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{}),
Expand Down Expand Up @@ -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
Expand All @@ -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),
),
},
},
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1428,23 +1406,23 @@ 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")
}
}

return nil
}
}

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)
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions website/docs/d/datasource_compute_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down Expand Up @@ -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.
Expand Down
13 changes: 10 additions & 3 deletions website/docs/r/compute_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).

Expand All @@ -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.

Expand Down
Loading