terraform-provider-google/website/docs/r/compute_subnetwork.html.markdown

233 lines
8.6 KiB
Markdown
Raw Normal View History

---
2018-06-19 20:56:06 +00:00
# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in
# .github/CONTRIBUTING.md.
#
# ----------------------------------------------------------------------------
layout: "google"
page_title: "Google: google_compute_subnetwork"
2018-06-19 20:56:06 +00:00
sidebar_current: "docs-google-compute-subnetwork"
description: |-
2018-06-19 20:56:06 +00:00
A VPC network is a virtual version of the traditional physical networks
that exist within and between physical data centers.
---
# google\_compute\_subnetwork
2018-06-19 20:56:06 +00:00
A VPC network is a virtual version of the traditional physical networks
that exist within and between physical data centers. A VPC network
provides connectivity for your Compute Engine virtual machine (VM)
instances, Container Engine containers, App Engine Flex services, and
other network-related resources.
2018-06-19 20:56:06 +00:00
Each GCP project contains one or more VPC networks. Each VPC network is a
global entity spanning all GCP regions. This global VPC network allows VM
instances and other resources to communicate with each other via internal,
private IP addresses.
2018-06-19 20:56:06 +00:00
Each VPC network is subdivided into subnets, and each subnet is contained
within a single region. You can have more than one subnet in a region for
a given VPC network. Each subnet has a contiguous private RFC1918 IP
space. You create instances, containers, and the like in these subnets.
When you create an instance, you must create it in a subnet, and the
instance draws its internal IP address from that subnet.
2018-06-19 20:56:06 +00:00
Virtual machine (VM) instances in a VPC network can communicate with
instances in all other subnets of the same VPC network, regardless of
region, using their RFC1918 private IP addresses. You can isolate portions
of the network, even entire subnets, using firewall rules.
2018-06-19 20:56:06 +00:00
To get more information about Subnetwork, see:
2018-06-19 20:56:06 +00:00
* [API documentation](https://cloud.google.com/compute/docs/reference/rest/beta/subnetworks)
* How-to Guides
* [Private Google Access](https://cloud.google.com/vpc/docs/configure-private-google-access)
* [Cloud Networking](https://cloud.google.com/vpc/docs/using-vpc)
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=subnetwork_basic&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Subnetwork Basic
2018-06-19 20:56:06 +00:00
```hcl
2018-09-24 22:35:43 +00:00
resource "google_compute_subnetwork" "network-with-private-secondary-ip-ranges" {
name = "test-subnetwork"
ip_cidr_range = "10.2.0.0/16"
region = "us-central1"
network = "${google_compute_network.custom-test.self_link}"
secondary_ip_range {
range_name = "tf-test-secondary-range-update1"
ip_cidr_range = "192.168.10.0/24"
2018-06-19 20:56:06 +00:00
}
2018-09-24 22:35:43 +00:00
}
2018-06-19 20:56:06 +00:00
2018-09-24 22:35:43 +00:00
resource "google_compute_network" "custom-test" {
name = "test-network"
auto_create_subnetworks = false
}
2018-06-19 20:56:06 +00:00
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=subnetwork_logging_config_beta&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Subnetwork Logging Config Beta
```hcl
resource "google_compute_subnetwork" "subnet-with-logging" {
provider = "google-beta"
name = "log-test-subnetwork"
ip_cidr_range = "10.2.0.0/16"
region = "us-central1"
network = "${google_compute_network.custom-test.self_link}"
enable_flow_logs = true
log_config {
aggregation_interval = "INTERVAL_10_MIN"
flow_sampling = 0.5
metadata = "INCLUDE_ALL_METADATA"
}
}
resource "google_compute_network" "custom-test" {
provider = "google-beta"
name = "log-test-network"
auto_create_subnetworks = false
}
provider "google-beta"{
region = "us-central1"
zone = "us-central1-a"
}
```
2018-06-19 20:56:06 +00:00
## Argument Reference
2018-06-19 20:56:06 +00:00
The following arguments are supported:
2018-06-19 20:56:06 +00:00
* `ip_cidr_range` -
(Required)
The range of internal addresses that are owned by this subnetwork.
Provide this property when you create the subnetwork. For example,
10.0.0.0/8 or 192.168.0.0/16. Ranges must be unique and
non-overlapping within a network. Only IPv4 is supported.
2018-06-19 20:56:06 +00:00
* `name` -
(Required)
The name of the resource, provided by the client when initially
creating the resource. The name must be 1-63 characters long, and
comply with RFC1035. Specifically, the name must be 1-63 characters
long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which
means the first character must be a lowercase letter, and all
following characters must be a dash, lowercase letter, or digit,
except the last character, which cannot be a dash.
2018-06-19 20:56:06 +00:00
* `network` -
(Required)
The network this subnet belongs to.
Only networks that are in the distributed mode can have subnetworks.
2018-05-02 18:51:34 +00:00
- - -
2018-06-19 20:56:06 +00:00
* `description` -
(Optional)
An optional description of this resource. Provide this property when
you create the resource. This field can be set only at resource
creation time.
2018-06-19 20:56:06 +00:00
* `enable_flow_logs` -
(Optional)
Whether to enable flow logging for this subnetwork.
2018-06-19 20:56:06 +00:00
* `secondary_ip_range` -
(Optional)
An array of configurations for secondary IP ranges for VM instances
contained in this subnetwork. The primary IP of such VM must belong
to the primary ipCidrRange of the subnetwork. The alias IPs may belong
to either primary or secondary ranges. Structure is documented below.
2018-06-19 20:56:06 +00:00
* `private_ip_google_access` -
(Optional)
When enabled, VMs in this subnetwork without external IP addresses can
access Google APIs and services by using Private Google Access.
2018-06-19 20:56:06 +00:00
* `region` -
(Optional)
URL of the GCP region for this subnetwork.
* `project` - (Optional) The ID of the project in which the resource belongs.
2018-06-19 20:56:06 +00:00
If it is not provided, the provider project is used.
The `secondary_ip_range` block supports:
2018-06-19 20:56:06 +00:00
* `range_name` -
(Required)
The name associated with this subnetwork secondary range, used
when adding an alias IP range to a VM instance. The name must
be 1-63 characters long, and comply with RFC1035. The name
must be unique within the subnetwork.
2018-06-19 20:56:06 +00:00
* `ip_cidr_range` -
(Required)
The range of IP addresses belonging to this subnetwork secondary
range. Provide this property when you create the subnetwork.
Ranges must be unique and non-overlapping with all primary and
secondary IP ranges within a network. Only IPv4 is supported.
## Attributes Reference
2018-06-19 20:56:06 +00:00
In addition to the arguments listed above, the following computed attributes are exported:
2018-06-19 20:56:06 +00:00
* `creation_timestamp` -
Creation timestamp in RFC3339 text format.
2018-06-19 20:56:06 +00:00
* `gateway_address` -
The gateway address for default routes to reach destination addresses
outside this subnetwork.
2018-06-19 20:56:06 +00:00
* `fingerprint` -
Fingerprint of this resource. This field is used internally during
updates of this resource.
* `self_link` - The URI of the created resource.
2018-06-19 20:56:06 +00:00
## Timeouts
This resource provides the following
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:
2018-06-19 20:56:06 +00:00
- `create` - Default is 6 minutes.
- `update` - Default is 6 minutes.
- `delete` - Default is 6 minutes.
## Import
2018-06-19 20:56:06 +00:00
Subnetwork can be imported using any of these accepted formats:
```
2018-06-19 20:56:06 +00:00
$ terraform import google_compute_subnetwork.default projects/{{project}}/regions/{{region}}/subnetworks/{{name}}
$ terraform import google_compute_subnetwork.default {{project}}/{{region}}/{{name}}
$ terraform import google_compute_subnetwork.default {{region}}/{{name}}
2018-06-19 20:56:06 +00:00
$ terraform import google_compute_subnetwork.default {{name}}
```
-> If you're importing a resource with beta features, make sure to include `-provider=google-beta`
as an argument so that Terraform uses the correct provider to import your resource.