forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NetworkPolicy resource to Vmwareengine
- Loading branch information
1 parent
2ca20a0
commit 8364b77
Showing
6 changed files
with
399 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
# Copyright 2023 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
--- !ruby/object:Api::Resource | ||
name: 'NetworkPolicy' | ||
base_url: 'projects/{{project}}/locations/{{location}}/networkPolicies' | ||
self_link: 'projects/{{project}}/locations/{{location}}/networkPolicies/{{name}}' | ||
create_url: 'projects/{{project}}/locations/{{location}}/networkPolicies?networkPolicyId={{name}}' | ||
update_verb: :PATCH | ||
references: !ruby/object:Api::Resource::ReferenceLinks | ||
api: 'https://cloud.google.com/vmware-engine/docs/reference/rest/v1/projects.locations.networkPolicies' | ||
description: | | ||
Represents a network policy resource. Network policies are regional resources. | ||
async: !ruby/object:Api::OpAsync | ||
operation: !ruby/object:Api::OpAsync::Operation | ||
path: "name" | ||
base_url: "{{op_id}}" | ||
wait_ms: 5000 | ||
timeouts: !ruby/object:Api::Timeouts | ||
insert_minutes: 60 | ||
update_minutes: 60 | ||
delete_minutes: 60 | ||
result: !ruby/object:Api::OpAsync::Result | ||
path: "response" | ||
status: !ruby/object:Api::OpAsync::Status | ||
path: "done" | ||
complete: true | ||
allowed: | ||
- true | ||
- false | ||
error: !ruby/object:Api::OpAsync::Error | ||
path: "error" | ||
message: "message" | ||
|
||
import_format: ["projects/{{project}}/locations/{{location}}/networkPolicies/{{name}}"] | ||
autogen_async: true | ||
|
||
examples: | ||
- !ruby/object:Provider::Terraform::Examples | ||
name: "vmware_engine_network_policy_basic" | ||
primary_resource_id: "vmw-engine-network-policy" | ||
vars: | ||
name: "sample-network-policy" | ||
test_env_vars: | ||
region: :REGION | ||
|
||
parameters: | ||
- !ruby/object:Api::Type::String | ||
name: "location" | ||
required: true | ||
immutable: true | ||
url_param_only: true | ||
description: | | ||
The resource name of the location (region) to create the new network policy in. | ||
Resource names are schemeless URIs that follow the conventions in https://cloud.google.com/apis/design/resource_names. | ||
For example: projects/my-project/locations/us-central1 | ||
- !ruby/object:Api::Type::String | ||
name: "name" | ||
required: true | ||
immutable: true | ||
url_param_only: true | ||
description: | | ||
The ID of the Network Policy. | ||
properties: | ||
- !ruby/object:Api::Type::Time | ||
name: 'createTime' | ||
output: true | ||
description: | | ||
Creation time of this resource. | ||
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and | ||
up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z". | ||
- !ruby/object:Api::Type::Time | ||
name: 'updateTime' | ||
output: true | ||
description: | | ||
Last updated time of this resource. | ||
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine | ||
fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z". | ||
- !ruby/object:Api::Type::String | ||
name: 'uid' | ||
output: true | ||
description: | | ||
System-generated unique identifier for the resource. | ||
- !ruby/object:Api::Type::String | ||
name: 'vmwareEngineNetworkCanonical' | ||
output: true | ||
description: | | ||
The canonical name of the VMware Engine network in the form: | ||
projects/{project_number}/locations/{location}/vmwareEngineNetworks/{vmwareEngineNetworkId} | ||
- !ruby/object:Api::Type::String | ||
name: 'edgeServicesCidr' | ||
required: true | ||
description: | | ||
IP address range in CIDR notation used to create internet access and external IP access. | ||
An RFC 1918 CIDR block, with a "/26" prefix, is required. The range cannot overlap with any | ||
prefixes either in the consumer VPC network or in use by the private clouds attached to that VPC network. | ||
- !ruby/object:Api::Type::String | ||
name: 'description' | ||
description: | | ||
User-provided description for this network policy. | ||
- !ruby/object:Api::Type::String | ||
name: 'vmwareEngineNetwork' | ||
description: | | ||
The relative resource name of the VMware Engine network. Specify the name in the following form: | ||
projects/{project}/locations/{location}/vmwareEngineNetworks/{vmwareEngineNetworkId} where {project} | ||
can either be a project number or a project ID. | ||
- !ruby/object:Api::Type::NestedObject | ||
name: 'internetAccess' | ||
description: | | ||
Network service that allows VMware workloads to access the internet. | ||
properties: | ||
- !ruby/object:Api::Type::Boolean | ||
name: enabled | ||
send_empty_value: true | ||
description: | | ||
True if the service is enabled; false otherwise. | ||
- !ruby/object:Api::Type::Enum | ||
name: 'state' | ||
description: | | ||
State of the service. New values may be added to this enum when appropriate. | ||
output: true | ||
values: | ||
- :UNPROVISIONED | ||
- :RECONCILING | ||
- :ACTIVE | ||
|
||
- !ruby/object:Api::Type::NestedObject | ||
name: 'externalIp' | ||
description: | | ||
Network service that allows External IP addresses to be assigned to VMware workloads. | ||
This service can only be enabled when internetAccess is also enabled. | ||
properties: | ||
- !ruby/object:Api::Type::Boolean | ||
name: enabled | ||
send_empty_value: true | ||
description: | | ||
True if the service is enabled; false otherwise. | ||
- !ruby/object:Api::Type::Enum | ||
name: 'state' | ||
description: | | ||
State of the service. New values may be added to this enum when appropriate. | ||
output: true | ||
values: | ||
- :UNPROVISIONED | ||
- :RECONCILING | ||
- :ACTIVE |
22 changes: 22 additions & 0 deletions
22
mmv1/templates/terraform/examples/vmware_engine_network_policy_basic.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
resource "google_vmwareengine_network" "network-policy-nw" { | ||
name = "standard-nw" | ||
location = "global" | ||
type = "STANDARD" | ||
description = "VMwareEngine standard network sample" | ||
} | ||
|
||
resource "google_vmwareengine_network_policy" "<%= ctx[:primary_resource_id] %>" { | ||
location = "<%= ctx[:test_env_vars]['region'] %>" | ||
name = "<%= ctx[:vars]['name'] %>" | ||
|
||
internet_access { | ||
enabled = true | ||
} | ||
|
||
external_ip { | ||
enabled = true | ||
} | ||
|
||
edge_services_cidr = "192.168.30.0/26" | ||
vmware_engine_network = google_vmwareengine_network.network-policy-nw.id | ||
} |
39 changes: 39 additions & 0 deletions
39
...d_party/terraform/services/vmwareengine/data_source_google_vmwareengine_network_policy.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package vmwareengine | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-google/google/tpgresource" | ||
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" | ||
) | ||
|
||
func DataSourceVmwareengineNetworkPolicy() *schema.Resource { | ||
|
||
dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceVmwareengineNetworkPolicy().Schema) | ||
tpgresource.AddRequiredFieldsToSchema(dsSchema, "location", "name") | ||
return &schema.Resource{ | ||
Read: dataSourceVmwareengineNetworkPolicyRead, | ||
Schema: dsSchema, | ||
} | ||
} | ||
|
||
func dataSourceVmwareengineNetworkPolicyRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*transport_tpg.Config) | ||
|
||
// Store the ID now | ||
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/networkPolicies/{{name}}") | ||
if err != nil { | ||
return fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
err = resourceVmwareengineNetworkPolicyRead(d, meta) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if d.Id() == "" { | ||
return fmt.Errorf("%s not found", id) | ||
} | ||
return nil | ||
} |
65 changes: 65 additions & 0 deletions
65
...ty/terraform/services/vmwareengine/data_source_google_vmwareengine_network_policy_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package vmwareengine_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
"github.com/hashicorp/terraform-provider-google/google/envvar" | ||
) | ||
|
||
func TestAccDataSourceVmwareengineNetworkPolicy_basic(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"region": envvar.GetTestRegionFromEnv(), | ||
"random_suffix": acctest.RandString(t, 10), | ||
} | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
CheckDestroy: testAccCheckVmwareengineNetworkPolicyDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccVmwareengineNetworkPolicy_ds(context), | ||
Check: resource.ComposeTestCheckFunc( | ||
acctest.CheckDataSourceStateMatchesResourceStateWithIgnores("data.google_vmwareengine_network_policy.ds", "google_vmwareengine_network_policy.vmw-engine-network-policy", map[string]struct{}{}), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccVmwareengineNetworkPolicy_ds(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
resource "google_vmwareengine_network" "network-policy-nw" { | ||
name = "tf-test-sample-nw%{random_suffix}" | ||
location = "global" | ||
type = "STANDARD" | ||
description = "VMwareEngine standard network sample" | ||
} | ||
resource "google_vmwareengine_network_policy" "vmw-engine-network-policy" { | ||
location = "%{region}" | ||
name = "tf-test-sample-network-policy%{random_suffix}" | ||
internet_access { | ||
enabled = true | ||
} | ||
external_ip { | ||
enabled = true | ||
} | ||
edge_services_cidr = "192.168.30.0/26" | ||
vmware_engine_network = google_vmwareengine_network.network-policy-nw.id | ||
} | ||
data "google_vmwareengine_network_policy" "ds" { | ||
name = google_vmwareengine_network_policy.vmw-engine-network-policy.name | ||
location = "%{region}" | ||
depends_on = [ | ||
google_vmwareengine_network_policy.vmw-engine-network-policy, | ||
] | ||
} | ||
`, context) | ||
} |
75 changes: 75 additions & 0 deletions
75
.../third_party/terraform/services/vmwareengine/resource_vmwareengine_network_policy_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package vmwareengine_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
"github.com/hashicorp/terraform-provider-google/google/envvar" | ||
) | ||
|
||
func TestAccVmwareengineNetworkPolicy_update(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"region": envvar.GetTestRegionFromEnv(), | ||
"random_suffix": acctest.RandString(t, 10), | ||
} | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
CheckDestroy: testAccCheckVmwareengineNetworkPolicyDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccVmwareengineNetworkPolicy_config(context, false, false), | ||
}, | ||
{ | ||
ResourceName: "google_vmwareengine_network_policy.vmw-engine-network-policy", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"location", "name"}, | ||
}, | ||
{ | ||
Config: testAccVmwareengineNetworkPolicy_config(context, true, true), | ||
}, | ||
{ | ||
ResourceName: "google_vmwareengine_network_policy.vmw-engine-network-policy", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"location", "name"}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccVmwareengineNetworkPolicy_config(context map[string]interface{}, internetAccess bool, externalIp bool) string { | ||
context["internet_access"] = internetAccess | ||
context["external_ip"] = externalIp | ||
|
||
return acctest.Nprintf(` | ||
resource "google_vmwareengine_network" "network-policy-nw" { | ||
name = "tf-test-sample-nw%{random_suffix}" | ||
location = "global" | ||
type = "STANDARD" | ||
description = "VMwareEngine standard network sample" | ||
} | ||
resource "google_vmwareengine_network_policy" "vmw-engine-network-policy" { | ||
location = "%{region}" | ||
name = "tf-test-sample-network-policy%{random_suffix}" | ||
internet_access { | ||
enabled = "%{internet_access}" | ||
} | ||
external_ip { | ||
enabled = "%{external_ip}" | ||
} | ||
edge_services_cidr = "192.168.30.0/26" | ||
vmware_engine_network = google_vmwareengine_network.network-policy-nw.id | ||
} | ||
`, context) | ||
} |
Oops, something went wrong.