Skip to content

Commit 72bba9c

Browse files
Shruti Shetyesagarp337
authored andcommitted
Added - Support for VTAP feature in vcn service
1 parent efef751 commit 72bba9c

30 files changed

+3598
-9
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {
5+
}
6+
7+
variable "user_ocid" {
8+
}
9+
10+
variable "fingerprint" {
11+
}
12+
13+
variable "private_key_path" {
14+
}
15+
16+
variable "compartment_ocid" {
17+
}
18+
19+
variable "region" {
20+
}
21+
22+
provider "oci" {
23+
tenancy_ocid = var.tenancy_ocid
24+
user_ocid = var.user_ocid
25+
fingerprint = var.fingerprint
26+
private_key_path = var.private_key_path
27+
region = var.region
28+
}
29+
30+
resource "oci_core_capture_filter" "example_capture_filter" {
31+
compartment_id = var.compartment_ocid
32+
display_name = "exampleCaptureFilter"
33+
filter_type = "VTAP"
34+
vtap_capture_filter_rules {
35+
traffic_direction = "INGRESS"
36+
}
37+
}
38+

examples/networking/vtap/vtap.tf

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {
5+
}
6+
7+
variable "user_ocid" {
8+
}
9+
10+
variable "fingerprint" {
11+
}
12+
13+
variable "private_key_path" {
14+
}
15+
16+
variable "compartment_ocid" {
17+
}
18+
19+
variable "region" {
20+
}
21+
22+
provider "oci" {
23+
tenancy_ocid = var.tenancy_ocid
24+
user_ocid = var.user_ocid
25+
fingerprint = var.fingerprint
26+
private_key_path = var.private_key_path
27+
region = var.region
28+
}
29+
30+
resource "oci_core_vcn" "example_vcn" {
31+
cidr_block = "10.1.0.0/16"
32+
compartment_id = var.compartment_ocid
33+
display_name = "exampleVCN"
34+
dns_label = "tfexamplevcn"
35+
}
36+
37+
resource "oci_core_capture_filter" "example_capture_filter" {
38+
compartment_id = var.compartment_ocid
39+
display_name = "exampleCaptureFilter"
40+
filter_type = "VTAP"
41+
vtap_capture_filter_rules {
42+
traffic_direction = "INGRESS"
43+
}
44+
}
45+
46+
// A regional subnet will not specify an Availability Domain
47+
resource "oci_core_subnet" "regional_subnet" {
48+
cidr_block = "10.1.1.0/24"
49+
display_name = "regionalSubnet"
50+
dns_label = "regionalsubnet"
51+
compartment_id = var.compartment_ocid
52+
vcn_id = oci_core_vcn.example_vcn.id
53+
security_list_ids = [oci_core_vcn.example_vcn.default_security_list_id]
54+
route_table_id = oci_core_vcn.example_vcn.default_route_table_id
55+
dhcp_options_id = oci_core_vcn.example_vcn.default_dhcp_options_id
56+
}
57+
58+
resource "oci_core_network_security_group" "test_network_security_group" {
59+
#Required
60+
compartment_id = var.compartment_ocid
61+
vcn_id = oci_core_vcn.example_vcn.id
62+
}
63+
64+
resource "oci_load_balancer" "lb1" {
65+
shape = "100Mbps"
66+
compartment_id = var.compartment_ocid
67+
68+
subnet_ids = [
69+
oci_core_subnet.regional_subnet.id,
70+
]
71+
72+
display_name = "lb1"
73+
is_private = true
74+
network_security_group_ids = [oci_core_network_security_group.test_network_security_group.id]
75+
}
76+
77+
resource "oci_core_vtap" "example_vtap" {
78+
compartment_id = var.compartment_ocid
79+
vcn_id = oci_core_vcn.example_vcn.id
80+
display_name = "exampleVtap"
81+
capture_filter_id = oci_core_capture_filter.example_capture_filter.id
82+
source_id = oci_load_balancer.lb1.id
83+
source_type = "LOAD_BALANCER"
84+
target_ip = "1.1.1.1"
85+
is_vtap_enabled = true
86+
}
87+

internal/integrationtest/core_capture_filter_test.go

Lines changed: 429 additions & 0 deletions
Large diffs are not rendered by default.

internal/integrationtest/core_vtap_test.go

Lines changed: 412 additions & 0 deletions
Large diffs are not rendered by default.

internal/provider/register_datasource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ func init() {
248248
RegisterDatasource("oci_core_byoip_allocated_ranges", tf_core.CoreByoipAllocatedRangesDataSource())
249249
RegisterDatasource("oci_core_byoip_range", tf_core.CoreByoipRangeDataSource())
250250
RegisterDatasource("oci_core_byoip_ranges", tf_core.CoreByoipRangesDataSource())
251+
RegisterDatasource("oci_core_capture_filter", tf_core.CoreCaptureFilterDataSource())
252+
RegisterDatasource("oci_core_capture_filters", tf_core.CoreCaptureFiltersDataSource())
251253
RegisterDatasource("oci_core_cluster_network", tf_core.CoreClusterNetworkDataSource())
252254
RegisterDatasource("oci_core_cluster_network_instances", tf_core.CoreClusterNetworkInstancesDataSource())
253255
RegisterDatasource("oci_core_cluster_networks", tf_core.CoreClusterNetworksDataSource())
@@ -362,6 +364,8 @@ func init() {
362364
RegisterDatasource("oci_core_volume_group_replicas", tf_core.CoreVolumeGroupReplicasDataSource())
363365
RegisterDatasource("oci_core_volume_groups", tf_core.CoreVolumeGroupsDataSource())
364366
RegisterDatasource("oci_core_volumes", tf_core.CoreVolumesDataSource())
367+
RegisterDatasource("oci_core_vtap", tf_core.CoreVtapDataSource())
368+
RegisterDatasource("oci_core_vtaps", tf_core.CoreVtapsDataSource())
365369
// data_connectivity service
366370
RegisterDatasource("oci_data_connectivity_registries", tf_data_connectivity.DataConnectivityRegistriesDataSource())
367371
RegisterDatasource("oci_data_connectivity_registry", tf_data_connectivity.DataConnectivityRegistryDataSource())

internal/provider/register_resource.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ func init() {
184184
RegisterResource("oci_core_app_catalog_subscription", tf_core.CoreAppCatalogSubscriptionResource())
185185
RegisterResource("oci_core_boot_volume", tf_core.CoreBootVolumeResource())
186186
RegisterResource("oci_core_boot_volume_backup", tf_core.CoreBootVolumeBackupResource())
187+
RegisterResource("oci_core_capture_filter", tf_core.CoreCaptureFilterResource())
187188
RegisterResource("oci_core_cluster_network", tf_core.CoreClusterNetworkResource())
188189
RegisterResource("oci_core_compute_capacity_reservation", tf_core.CoreComputeCapacityReservationResource())
189190
RegisterResource("oci_core_compute_image_capability_schema", tf_core.CoreComputeImageCapabilitySchemaResource())
@@ -241,6 +242,7 @@ func init() {
241242
RegisterResource("oci_core_volume_backup_policy_assignment", tf_core.CoreVolumeBackupPolicyAssignmentResource())
242243
RegisterResource("oci_core_volume_group", tf_core.CoreVolumeGroupResource())
243244
RegisterResource("oci_core_volume_group_backup", tf_core.CoreVolumeGroupBackupResource())
245+
RegisterResource("oci_core_vtap", tf_core.CoreVtapResource())
244246
// data_connectivity service
245247
RegisterResource("oci_data_connectivity_registry", tf_data_connectivity.DataConnectivityRegistryResource())
246248
RegisterResource("oci_data_connectivity_registry_connection", tf_data_connectivity.DataConnectivityRegistryConnectionResource())

internal/resourcediscovery/export_definitions.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,26 @@ var exportCoreDrgRouteTableRouteRuleHints = &TerraformResourceHints{
10131013
resourceAbbreviation: "drg_route_table_route_rule",
10141014
}
10151015

1016+
var exportCoreCaptureFilterHints = &TerraformResourceHints{
1017+
resourceClass: "oci_core_capture_filter",
1018+
datasourceClass: "oci_core_capture_filters",
1019+
datasourceItemsAttr: "capture_filters",
1020+
resourceAbbreviation: "capture_filter",
1021+
discoverableLifecycleStates: []string{
1022+
string(oci_core.CaptureFilterLifecycleStateAvailable),
1023+
},
1024+
}
1025+
1026+
var exportCoreVtapHints = &TerraformResourceHints{
1027+
resourceClass: "oci_core_vtap",
1028+
datasourceClass: "oci_core_vtaps",
1029+
datasourceItemsAttr: "vtaps",
1030+
resourceAbbreviation: "vtap",
1031+
discoverableLifecycleStates: []string{
1032+
string(oci_core.VtapLifecycleStateAvailable),
1033+
},
1034+
}
1035+
10161036
var exportDataConnectivityRegistryHints = &TerraformResourceHints{
10171037
resourceClass: "oci_data_connectivity_registry",
10181038
datasourceClass: "oci_data_connectivity_registries",

internal/resourcediscovery/export_graphs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ var coreResourceGraph = TerraformResourceGraph{
335335
{TerraformResourceHints: exportCoreVolumeGroupBackupHints},
336336
{TerraformResourceHints: exportCoreVolumeHints},
337337
{TerraformResourceHints: exportCorePublicIpPoolHints},
338+
{TerraformResourceHints: exportCoreCaptureFilterHints},
339+
{TerraformResourceHints: exportCoreVtapHints},
338340
},
339341
"oci_core_boot_volume": {
340342
{
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package core
5+
6+
import (
7+
"context"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
oci_core "github.com/oracle/oci-go-sdk/v65/core"
11+
12+
"github.com/terraform-providers/terraform-provider-oci/internal/client"
13+
"github.com/terraform-providers/terraform-provider-oci/internal/tfresource"
14+
)
15+
16+
func CoreCaptureFilterDataSource() *schema.Resource {
17+
fieldMap := make(map[string]*schema.Schema)
18+
fieldMap["capture_filter_id"] = &schema.Schema{
19+
Type: schema.TypeString,
20+
Required: true,
21+
}
22+
return tfresource.GetSingularDataSourceItemSchema(CoreCaptureFilterResource(), fieldMap, readSingularCoreCaptureFilter)
23+
}
24+
25+
func readSingularCoreCaptureFilter(d *schema.ResourceData, m interface{}) error {
26+
sync := &CoreCaptureFilterDataSourceCrud{}
27+
sync.D = d
28+
sync.Client = m.(*client.OracleClients).VirtualNetworkClient()
29+
30+
return tfresource.ReadResource(sync)
31+
}
32+
33+
type CoreCaptureFilterDataSourceCrud struct {
34+
D *schema.ResourceData
35+
Client *oci_core.VirtualNetworkClient
36+
Res *oci_core.GetCaptureFilterResponse
37+
}
38+
39+
func (s *CoreCaptureFilterDataSourceCrud) VoidState() {
40+
s.D.SetId("")
41+
}
42+
43+
func (s *CoreCaptureFilterDataSourceCrud) Get() error {
44+
request := oci_core.GetCaptureFilterRequest{}
45+
46+
if captureFilterId, ok := s.D.GetOkExists("capture_filter_id"); ok {
47+
tmp := captureFilterId.(string)
48+
request.CaptureFilterId = &tmp
49+
}
50+
51+
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(false, "core")
52+
53+
response, err := s.Client.GetCaptureFilter(context.Background(), request)
54+
if err != nil {
55+
return err
56+
}
57+
58+
s.Res = &response
59+
return nil
60+
}
61+
62+
func (s *CoreCaptureFilterDataSourceCrud) SetData() error {
63+
if s.Res == nil {
64+
return nil
65+
}
66+
67+
s.D.SetId(*s.Res.Id)
68+
69+
if s.Res.CompartmentId != nil {
70+
s.D.Set("compartment_id", *s.Res.CompartmentId)
71+
}
72+
73+
if s.Res.DefinedTags != nil {
74+
s.D.Set("defined_tags", tfresource.DefinedTagsToMap(s.Res.DefinedTags))
75+
}
76+
77+
if s.Res.DisplayName != nil {
78+
s.D.Set("display_name", *s.Res.DisplayName)
79+
}
80+
81+
s.D.Set("filter_type", s.Res.FilterType)
82+
83+
s.D.Set("freeform_tags", s.Res.FreeformTags)
84+
85+
s.D.Set("state", s.Res.LifecycleState)
86+
87+
if s.Res.TimeCreated != nil {
88+
s.D.Set("time_created", s.Res.TimeCreated.String())
89+
}
90+
91+
vtapCaptureFilterRules := []interface{}{}
92+
for _, item := range s.Res.VtapCaptureFilterRules {
93+
vtapCaptureFilterRules = append(vtapCaptureFilterRules, VtapCaptureFilterRuleDetailsToMap(item))
94+
}
95+
s.D.Set("vtap_capture_filter_rules", vtapCaptureFilterRules)
96+
97+
return nil
98+
}

0 commit comments

Comments
 (0)