Skip to content

Commit 4494d88

Browse files
Girish JambagiMaxrovr
authored andcommitted
Added - Support for Zero Trust Packet Routing
1 parent 3278f5e commit 4494d88

20 files changed

+2220
-11
lines changed

examples/zpr/main.tf

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {}
5+
variable "user_ocid" {}
6+
variable "fingerprint" {}
7+
variable "private_key_path" {}
8+
variable "region" {}
9+
variable "compartment_id" {}
10+
11+
variable "configuration_defined_tags" {
12+
default = {}
13+
}
14+
15+
variable "configuration_freeform_tags" {
16+
default = { "Department" = "Finance" }
17+
}
18+
19+
variable "configuration_zpr_status" {
20+
default = "ENABLED"
21+
}
22+
23+
variable "zpr_policy_description" {
24+
default = "description"
25+
}
26+
27+
variable "zpr_policy_defined_tags" {
28+
default = {}
29+
}
30+
31+
variable "zpr_policy_freeform_tags" {
32+
default = { "Department" = "Finance" }
33+
}
34+
35+
variable "zpr_policy_name" {
36+
default = "name"
37+
}
38+
39+
variable "zpr_policy_state" {
40+
default = "ACTIVE"
41+
}
42+
43+
variable "zpr_policy_statements" {
44+
default = []
45+
}
46+
47+
provider "oci" {
48+
tenancy_ocid = var.tenancy_ocid
49+
user_ocid = var.user_ocid
50+
fingerprint = var.fingerprint
51+
private_key_path = var.private_key_path
52+
region = var.region
53+
}
54+
55+
resource "oci_zpr_configuration" "test_configuration" {
56+
#Required
57+
compartment_id = var.tenancy_ocid
58+
59+
#Optional
60+
defined_tags = var.configuration_defined_tags
61+
freeform_tags = var.configuration_freeform_tags
62+
}
63+
64+
data "oci_zpr_configuration" "test_configuration" {
65+
#Required
66+
compartment_id = var.tenancy_ocid
67+
}
68+
69+
resource "oci_zpr_zpr_policy" "test_zpr_policy" {
70+
#Required
71+
compartment_id = var.tenancy_ocid
72+
description = var.zpr_policy_description
73+
name = var.zpr_policy_name
74+
statements = var.zpr_policy_statements
75+
76+
#Optional
77+
defined_tags = var.zpr_policy_defined_tags
78+
freeform_tags = var.zpr_policy_freeform_tags
79+
}
80+
81+
data "oci_zpr_zpr_policies" "test_zpr_policies" {
82+
#Required
83+
compartment_id = var.tenancy_ocid
84+
85+
#Optional
86+
name = var.zpr_policy_name
87+
state = var.zpr_policy_state
88+
}
89+
90+
data "oci_zpr_zpr_policy" "test_zpr_policy" {
91+
#Required
92+
zpr_policy_id = oci_zpr_zpr_policy.test_zpr_policy.id
93+
}

internal/client/zpr_clients.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package client
5+
6+
import (
7+
oci_zpr "github.com/oracle/oci-go-sdk/v65/zpr"
8+
9+
oci_common "github.com/oracle/oci-go-sdk/v65/common"
10+
)
11+
12+
func init() {
13+
RegisterOracleClient("oci_zpr.ZprClient", &OracleClient{InitClientFn: initZprZprClient})
14+
}
15+
16+
func initZprZprClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient, serviceClientOverrides ServiceClientOverrides) (interface{}, error) {
17+
client, err := oci_zpr.NewZprClientWithConfigurationProvider(configProvider)
18+
if err != nil {
19+
return nil, err
20+
}
21+
err = configureClient(&client.BaseClient)
22+
if err != nil {
23+
return nil, err
24+
}
25+
26+
if serviceClientOverrides.HostUrlOverride != "" {
27+
client.Host = serviceClientOverrides.HostUrlOverride
28+
}
29+
return &client, nil
30+
}
31+
32+
func (m *OracleClients) ZprClient() *oci_zpr.ZprClient {
33+
return m.GetClient("oci_zpr.ZprClient").(*oci_zpr.ZprClient)
34+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package integrationtest
5+
6+
import (
7+
"fmt"
8+
"strconv"
9+
"testing"
10+
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
12+
"github.com/oracle/terraform-provider-oci/internal/resourcediscovery"
13+
14+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
15+
"github.com/oracle/terraform-provider-oci/httpreplay"
16+
"github.com/oracle/terraform-provider-oci/internal/acctest"
17+
"github.com/oracle/terraform-provider-oci/internal/utils"
18+
)
19+
20+
var (
21+
ignoreChangesZprConfigurationRepresentation = map[string]interface{}{
22+
"ignore_changes": acctest.Representation{RepType: acctest.Required, Create: []string{"defined_tags", "freeform_tags", "system_tags"}},
23+
}
24+
25+
ZprConfigurationRequiredOnlyResource = ZprConfigurationResourceDependencies +
26+
acctest.GenerateResourceFromRepresentationMap("oci_zpr_configuration", "test_configuration", acctest.Required, acctest.Create, ZprConfigurationRepresentation)
27+
28+
ZprConfigurationResourceConfig = ZprConfigurationResourceDependencies +
29+
acctest.GenerateResourceFromRepresentationMap("oci_zpr_configuration", "test_configuration", acctest.Optional, acctest.Update, ZprConfigurationRepresentation)
30+
31+
ZprConfigurationSingularDataSourceRepresentation = map[string]interface{}{
32+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.tenancy_ocid}`},
33+
}
34+
35+
ZprConfigurationRepresentation = map[string]interface{}{
36+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.tenancy_ocid}`},
37+
"defined_tags": acctest.Representation{RepType: acctest.Required, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
38+
"freeform_tags": acctest.Representation{RepType: acctest.Required, Create: map[string]string{"Department": "Finance"}, Update: map[string]string{"Department": "Accounting"}},
39+
"lifecycle": acctest.RepresentationGroup{RepType: acctest.Required, Group: ignoreChangesZprConfigurationRepresentation},
40+
}
41+
42+
ZprConfigurationResourceDependencies = DefinedTagsDependencies
43+
)
44+
45+
// issue-routing-tag: zpr/default
46+
func TestZprConfigurationResource_basic(t *testing.T) {
47+
httpreplay.SetScenario("TestZprConfigurationResource_basic")
48+
defer httpreplay.SaveScenario()
49+
50+
config := acctest.ProviderTestConfig()
51+
52+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
53+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
54+
tenancyId := utils.GetEnvSettingWithBlankDefault("tenancy_ocid")
55+
56+
resourceName := "oci_zpr_configuration.test_configuration"
57+
singularDatasourceName := "data.oci_zpr_configuration.test_configuration"
58+
59+
// Save TF content to Create resource with optional properties. This has to be exactly the same as the config part in the "create with optionals" step in the test.
60+
acctest.SaveConfigContent(config+compartmentIdVariableStr+ZprConfigurationResourceDependencies+
61+
acctest.GenerateResourceFromRepresentationMap("oci_zpr_configuration", "test_configuration", acctest.Optional, acctest.Create, ZprConfigurationRepresentation), "zpr", "configuration", t)
62+
63+
acctest.ResourceTest(t, nil, []resource.TestStep{
64+
// Configuration can only be created once
65+
// verify Create
66+
{
67+
Config: config + compartmentIdVariableStr + ZprConfigurationResourceDependencies +
68+
acctest.GenerateResourceFromRepresentationMap("oci_zpr_configuration", "test_configuration", acctest.Required, acctest.Create, ZprConfigurationRepresentation),
69+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
70+
resource.TestCheckResourceAttr(resourceName, "compartment_id", tenancyId),
71+
resource.TestCheckResourceAttr(singularDatasourceName, "freeform_tags.%", "1"),
72+
resource.TestCheckResourceAttrSet(resourceName, "id"),
73+
resource.TestCheckResourceAttrSet(resourceName, "state"),
74+
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
75+
resource.TestCheckResourceAttrSet(resourceName, "time_updated"),
76+
resource.TestCheckResourceAttr(resourceName, "zpr_status", "ENABLED"),
77+
78+
func(s *terraform.State) (err error) {
79+
resId, err := acctest.FromInstanceState(s, resourceName, "id")
80+
if isEnableExportCompartment, _ := strconv.ParseBool(utils.GetEnvSettingWithDefault("enable_export_compartment", "true")); isEnableExportCompartment {
81+
if errExport := resourcediscovery.TestExportCompartmentWithResourceName(&resId, &compartmentId, resourceName); errExport != nil {
82+
return errExport
83+
}
84+
}
85+
return err
86+
},
87+
),
88+
},
89+
90+
// verify singular datasource
91+
{
92+
Config: config +
93+
acctest.GenerateDataSourceFromRepresentationMap("oci_zpr_configuration", "test_configuration", acctest.Required, acctest.Create, ZprConfigurationSingularDataSourceRepresentation) +
94+
compartmentIdVariableStr + ZprConfigurationResourceConfig,
95+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
96+
resource.TestCheckResourceAttr(singularDatasourceName, "compartment_id", tenancyId),
97+
// TODO: Service bug - Tags are not returned in GET call - DATASEC-3045
98+
//resource.TestCheckResourceAttr(singularDatasourceName, "freeform_tags.%", "1"),
99+
resource.TestCheckResourceAttrSet(singularDatasourceName, "id"),
100+
resource.TestCheckResourceAttrSet(singularDatasourceName, "state"),
101+
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_created"),
102+
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_updated"),
103+
resource.TestCheckResourceAttr(singularDatasourceName, "zpr_status", "ENABLED"),
104+
),
105+
},
106+
107+
// verify resource import
108+
{
109+
Config: config + ZprConfigurationRequiredOnlyResource,
110+
ImportState: true,
111+
ImportStateIdFunc: getZprConfigurationConfigurationId(resourceName),
112+
ImportStateVerify: true,
113+
ImportStateVerifyIgnore: []string{"defined_tags", "freeform_tags"},
114+
ResourceName: resourceName,
115+
},
116+
117+
// delete
118+
{
119+
Config: config + compartmentIdVariableStr + ZprConfigurationResourceDependencies,
120+
},
121+
})
122+
}
123+
124+
func getZprConfigurationConfigurationId(resourceName string) resource.ImportStateIdFunc {
125+
return func(s *terraform.State) (string, error) {
126+
rs, ok := s.RootModule().Resources[resourceName]
127+
if !ok {
128+
return "", fmt.Errorf("not found: %s", resourceName)
129+
}
130+
131+
return fmt.Sprintf("%s/%s", rs.Primary.Attributes["compartment_id"], rs.Primary.Attributes["id"]), nil
132+
}
133+
}

0 commit comments

Comments
 (0)