_This issue was originally opened by @alexandershelega as hashicorp/terraform#16095. It was migrated here as a result of the provider split. The original body of the issue is below._
Hi guys, i want to create static ip and map it to host, address was create successfully, and i see it in google console, but when i try to create compute node i receive this error.
google_compute_instance.gcp-test-ip: Error creating instance: googleapi: Error 400: Invalid value for field 'resource.networkInterfaces[0].accessConfigs[0].natIP': 'gcp-test-ip'. The specified external IP address 'gcp-test-ip' was not found in region 'us-east1'., invalid
my terrafor config
resource "google_compute_address" "gcp-test-ip" {
name = "gcp-test-ip"
region = "us-east1"
}
resource "google_compute_instance" "gcp-test-ip" {
name = "gcp-test-ip"
machine_type = "custom-2-2048"
zone = "us-east1-c"
boot_disk {
initialize_params {
image = "ubuntu-1404-trusty-v20170818"
size = 30
}
}
network_interface {
network = "default"
access_config {
// Ephemeral IP
nat_ip = "${google_compute_address.gcp-test-ip.name}"
}
}
}
Hey @alexandershelega, you want to use the address property rather than the name property, so your config should look like:
nat_ip = "${google_compute_address.gcp-test-ip.address}" instead. I'm going to go ahead and close this issue but let me know if that doesn't work and I'll reopen it!
Hi,
I also have a couple of issues in network_interface while creating a compute engine in GCP using terraform.
Issue-1:
Error: google_compute_instance.virtual_instance: Error creating network interfaces: exactly one of network or subnetwork must be provided
network_interface {
network = "test-vpc" // Custom VPC
subnetwork = "${var.subnet_self_link}"
access_config {}
}
Then I comment out subnetwork and run `terraform apply` with below code is also giving error.
network_interface {
network = "test-vpc" // Custom VPC
//subnetwork = "${var.subnet_self_link}"
access_config {}
}
Error: google_compute_instance.virtual_instance: Error creating instance: googleapi: Error 400: Invalid value for field 'resource.networkInterfaces[0]': ''. Subnetwork should be specified for custom subnetmode network, invalid
Then I comment out network and run terraform for below code is working fine. And also when I used a default VPC it's working fine.
network_interface {
//network = "test-vpc" // Custom VPC
subnetwork = "${var.subnet_self_link}"
access_config {}
}
network_interface {
network = "default" // Default VPC
//subnetwork = "${var.subnet_self_link}"
access_config {}
}
Issue-2:
Error: google_compute_instance.virtual_instance: Error creating instance: googleapi: Error 400: Invalid value for field 'resource.networkInterfaces[0].accessConfigs[0].natIP': '10.160.0.2'. The specified external IP address '10.160.0.2' was not found in region 'asia-south1'., invalid
network_interface {
subnetwork = "${var.subnet_self_link}"
access_config {
nat_ip = "${google_compute_address.static.address}"
}
}
resource "google_compute_address" "static" {
name = "${var.private_ip_name}"
address_type = "INTERNAL"
region = "asia-south1"
}
With the Same thing, I modified the above code and run terraform with below config getting the same error.
```network_interface {
network = "test-vpc" // Custom VPC
access_config {
nat_ip = "${google_compute_address.static.address}"
}
}
resource "google_compute_address" "static" {
name = "${var.private_ip_name}"
address_type = "INTERNAL"
region = "asia-south1"
}
Then i tired with defaut VPC and nat_ip. it's working fine.
network_interface {
network = "default"
access_config {
nat_ip = "${google_compute_address.static.address}"
}
}
resource "google_compute_address" "static" {
name = "${var.private_ip_name}"
address_type = "INTERNAL"
region = "asia-south1"
}
```
Questions:
Hey @Na-Sathish, you should specify the subnetwork you'd like the address created in in the google_compute_address resource.
(Also in the future, if you're experiencing an issue I'd recommend filing a new issue or finding an existing open one. I happened to get an email about this one because I was subscribed to it, but we don't have people regularly looking at issue that have already been closed)
Hi @danawillow,
Yeah, I tried with below code also giving the same error,
resource "google_compute_address" "static" {
name = "${var.kafka_private_ip_name}"
subnetwork = "${var.subnet_self_link}"
address_type = "INTERNAL"
region = "asia-south1"
}
network_interface {
subnetwork = "${var.subnet_self_link}"
access_config {
nat_ip = "${google_compute_address.static.address}"
}
}
Error:
Terraform Info after Creating google_compute_address :
network_interface.#: "" => "1"
network_interface.0.access_config.#: "" => "1"
network_interface.0.access_config.0.assigned_nat_ip: "" => "<computed>"
network_interface.0.access_config.0.nat_ip: "" => "10.11.0.2"
network_interface.0.access_config.0.network_tier: "" => "<computed>"
network_interface.0.address: "" => "<computed>"
network_interface.0.name: "" => "<computed>"
network_interface.0.network_ip: "" => "<computed>"
network_interface.0.subnetwork: "" => "projects/test-project/regions/asia-south1/subnetworks/test-subnet"
network_interface.0.subnetwork_project: "" => "<computed>"
@Na-Sathish, your google_compute_address creates internal address. If you need external address, remove subnetwork, address_type and region from the resource.
I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!
Most helpful comment
Hey @alexandershelega, you want to use the
addressproperty rather than thenameproperty, so your config should look like:nat_ip = "${google_compute_address.gcp-test-ip.address}"instead. I'm going to go ahead and close this issue but let me know if that doesn't work and I'll reopen it!