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

Add Network Policy resource to Vmwareengine #9514

Merged
merged 1 commit into from
Nov 30, 2023
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
177 changes: 177 additions & 0 deletions mmv1/products/vmwareengine/NetworkPolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# 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
- !ruby/object:Provider::Terraform::Examples
name: "vmware_engine_network_policy_full"
primary_resource_id: "vmw-engine-network-policy"
vars:
name: "sample-network-policy-full"
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'
required: true
immutable: true
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.
default_from_api: true
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.
default_from_api: true
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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'] %>"
edge_services_cidr = "192.168.30.0/26"
vmware_engine_network = google_vmwareengine_network.network-policy-nw.id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "google_vmwareengine_network" "network-policy-nw" {
name = "standard-full-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'] %>"
edge_services_cidr = "192.168.30.0/26"
vmware_engine_network = google_vmwareengine_network.network-policy-nw.id
description = "Sample Network Policy"
internet_access {
enabled = true
}
external_ip {
enabled = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ var handwrittenDatasources = map[string]*schema.Resource{
<% end -%>
"google_vmwareengine_network": vmwareengine.DataSourceVmwareengineNetwork(),
"google_vmwareengine_network_peering": vmwareengine.DataSourceVmwareengineNetworkPeering(),
"google_vmwareengine_network_policy": vmwareengine.DataSourceVmwareengineNetworkPolicy(),
"google_vmwareengine_private_cloud": vmwareengine.DataSourceVmwareenginePrivateCloud(),

// ####### END handwritten datasources ###########
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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")
tpgresource.AddOptionalFieldsToSchema(dsSchema, "project")
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
}
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-ds-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-ds-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)
}
Loading