Skip to content

Commit 4d495c0

Browse files
Xinhao ZhouKhalid-Chaudhry
authored andcommitted
Added - startCredentialRotation, completeCredentialRotation, getCredentialRotationStatus terraform implementation tests and examples
1 parent 584c169 commit 4d495c0

16 files changed

+1168
-1
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// Copyright (c) 2017, 2023, 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+
default = "us-ashburn-1"
10+
}
11+
variable "compartment_ocid" {}
12+
13+
variable "cluster_start_credential_rotation_management_auto_completion_delay_duration" {
14+
default = "P5D"
15+
}
16+
17+
provider "oci" {
18+
tenancy_ocid = var.tenancy_ocid
19+
user_ocid = var.user_ocid
20+
fingerprint = var.fingerprint
21+
private_key_path = var.private_key_path
22+
region = var.region
23+
}
24+
25+
data "oci_identity_availability_domain" "ad1" {
26+
compartment_id = var.tenancy_ocid
27+
ad_number = 1
28+
}
29+
30+
data "oci_identity_availability_domain" "ad2" {
31+
compartment_id = var.tenancy_ocid
32+
ad_number = 2
33+
}
34+
35+
data "oci_containerengine_cluster_option" "test_cluster_option" {
36+
cluster_option_id = "all"
37+
}
38+
39+
resource "oci_core_vcn" "test_vcn" {
40+
cidr_block = "10.0.0.0/16"
41+
compartment_id = var.compartment_ocid
42+
display_name = "tfVcnForClusters"
43+
}
44+
45+
resource "oci_core_internet_gateway" "test_ig" {
46+
compartment_id = var.compartment_ocid
47+
display_name = "tfClusterInternetGateway"
48+
vcn_id = oci_core_vcn.test_vcn.id
49+
}
50+
51+
resource "oci_core_route_table" "test_route_table" {
52+
compartment_id = var.compartment_ocid
53+
vcn_id = oci_core_vcn.test_vcn.id
54+
display_name = "tfClustersRouteTable"
55+
56+
route_rules {
57+
destination = "0.0.0.0/0"
58+
destination_type = "CIDR_BLOCK"
59+
network_entity_id = oci_core_internet_gateway.test_ig.id
60+
}
61+
}
62+
63+
resource "oci_core_subnet" "clusterSubnet_1" {
64+
#Required
65+
availability_domain = data.oci_identity_availability_domain.ad1.name
66+
cidr_block = "10.0.20.0/24"
67+
compartment_id = var.compartment_ocid
68+
vcn_id = oci_core_vcn.test_vcn.id
69+
70+
# Provider code tries to maintain compatibility with old versions.
71+
security_list_ids = [oci_core_vcn.test_vcn.default_security_list_id]
72+
display_name = "tfSubNet1ForClusters"
73+
route_table_id = oci_core_route_table.test_route_table.id
74+
}
75+
76+
resource "oci_core_subnet" "clusterSubnet_2" {
77+
#Required
78+
availability_domain = data.oci_identity_availability_domain.ad2.name
79+
cidr_block = "10.0.21.0/24"
80+
compartment_id = var.compartment_ocid
81+
vcn_id = oci_core_vcn.test_vcn.id
82+
display_name = "tfSubNet1ForClusters"
83+
84+
# Provider code tries to maintain compatibility with old versions.
85+
security_list_ids = [oci_core_vcn.test_vcn.default_security_list_id]
86+
route_table_id = oci_core_route_table.test_route_table.id
87+
}
88+
89+
resource "oci_containerengine_cluster" "test_cluster" {
90+
#Required
91+
compartment_id = var.compartment_ocid
92+
kubernetes_version = reverse(data.oci_containerengine_cluster_option.test_cluster_option.kubernetes_versions)[0]
93+
name = "tfTestCluster"
94+
vcn_id = oci_core_vcn.test_vcn.id
95+
96+
#Optional
97+
options {
98+
service_lb_subnet_ids = [oci_core_subnet.clusterSubnet_1.id, oci_core_subnet.clusterSubnet_2.id]
99+
100+
#Optional
101+
add_ons {
102+
#Optional
103+
is_kubernetes_dashboard_enabled = "true"
104+
is_tiller_enabled = "true"
105+
}
106+
107+
admission_controller_options {
108+
#Optional
109+
is_pod_security_policy_enabled = false
110+
}
111+
112+
kubernetes_network_config {
113+
#Optional
114+
pods_cidr = "10.1.0.0/16"
115+
services_cidr = "10.2.0.0/16"
116+
}
117+
}
118+
}
119+
120+
// start credential rotation on a cluster
121+
resource "oci_containerengine_cluster_start_credential_rotation_management" "test_cluster_start_credential_rotation_management" {
122+
#Required
123+
auto_completion_delay_duration = var.cluster_start_credential_rotation_management_auto_completion_delay_duration
124+
cluster_id = oci_containerengine_cluster.test_cluster.id
125+
}
126+
127+
// get credential rotation status
128+
data "oci_containerengine_cluster_credential_rotation_status" "test_cluster_credential_rotation_status" {
129+
#Required
130+
cluster_id = oci_containerengine_cluster.test_cluster.id
131+
}
132+
133+
// complete credential rotation on a cluster
134+
resource "oci_containerengine_cluster_complete_credential_rotation_management" "test_cluster_complete_credential_rotation_management" {
135+
#Required
136+
cluster_id = oci_containerengine_cluster.test_cluster.id
137+
depends_on = [oci_containerengine_cluster_start_credential_rotation_management.test_cluster_start_credential_rotation_management]
138+
}
139+

examples/container_engine/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ resource "oci_containerengine_node_pool" "test_flex_shape_node_pool" {
289289

290290
node_source_details {
291291
#Required
292-
image_id = local.oracle_linux_images.0
292+
image_id = local.image_id
293293
source_type = "IMAGE"
294294
}
295295

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright (c) 2017, 2023, 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+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
11+
12+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
13+
14+
"github.com/oracle/terraform-provider-oci/httpreplay"
15+
"github.com/oracle/terraform-provider-oci/internal/acctest"
16+
17+
"github.com/oracle/terraform-provider-oci/internal/utils"
18+
)
19+
20+
var (
21+
ContainerengineClusterCompleteCredentialRotationManagementRepresentation = map[string]interface{}{
22+
"cluster_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_containerengine_cluster.test_cluster.id}`},
23+
}
24+
)
25+
26+
// issue-routing-tag: containerengine/default
27+
func TestContainerengineClusterCompleteCredentialRotationManagementResource_basic(t *testing.T) {
28+
httpreplay.SetScenario("TestContainerengineClusterCompleteCredentialRotationManagementResource_basic")
29+
defer httpreplay.SaveScenario()
30+
31+
config := acctest.ProviderTestConfig()
32+
33+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
34+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
35+
36+
resourceName := "oci_containerengine_cluster.test_cluster"
37+
singularDatasourceName := "data.oci_containerengine_cluster_credential_rotation_status.test_cluster_credential_rotation_status"
38+
39+
// Save TF content to Create resource with only required properties. This has to be exactly the same as the config part in the create step in the test.
40+
acctest.SaveConfigContent(config+compartmentIdVariableStr+ContainerengineClusterResourceDependencies+
41+
acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster_complete_credential_rotation_management", "test_cluster_complete_credential_rotation_management", acctest.Required, acctest.Create, ContainerengineClusterCompleteCredentialRotationManagementRepresentation), "containerengine", "clusterCompleteCredentialRotationManagement", t)
42+
43+
acctest.ResourceTest(t, nil, []resource.TestStep{
44+
// create cluster
45+
{
46+
Config: config +
47+
acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", acctest.Optional, acctest.Create, ContainerengineClusterRepresentationForCredentialRotation) +
48+
compartmentIdVariableStr + ContainerengineClusterResourceDependencies,
49+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
50+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
51+
resource.TestCheckResourceAttrSet(resourceName, "kubernetes_version"),
52+
resource.TestCheckResourceAttr(resourceName, "name", "name"),
53+
resource.TestCheckResourceAttrSet(resourceName, "vcn_id"),
54+
resource.TestCheckResourceAttrSet(resourceName, "metadata.0.time_credential_expiration"),
55+
56+
func(s *terraform.State) (err error) {
57+
_, err = acctest.FromInstanceState(s, resourceName, "id")
58+
return err
59+
},
60+
),
61+
},
62+
63+
// start rotation
64+
{
65+
Config: config +
66+
acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", acctest.Optional, acctest.Create, ContainerengineClusterRepresentationForCredentialRotation) +
67+
compartmentIdVariableStr + ContainerengineClusterResourceDependencies +
68+
acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster_start_credential_rotation_management", "test_cluster_start_credential_rotation_management", acctest.Required, acctest.Create, ContainerengineClusterStartCredentialRotationManagementRepresentation),
69+
},
70+
71+
// verify rotation status
72+
{
73+
Config: config +
74+
acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", acctest.Optional, acctest.Create, ContainerengineClusterRepresentationForCredentialRotation) +
75+
compartmentIdVariableStr + ContainerengineClusterResourceDependencies +
76+
acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster_start_credential_rotation_management", "test_cluster_start_credential_rotation_management", acctest.Required, acctest.Create, ContainerengineClusterStartCredentialRotationManagementRepresentation) +
77+
acctest.GenerateDataSourceFromRepresentationMap("oci_containerengine_cluster_credential_rotation_status", "test_cluster_credential_rotation_status",
78+
acctest.Optional, acctest.Create, ContainerengineClusterCredentialRotationStatusSingularDataSourceRepresentation),
79+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
80+
resource.TestCheckResourceAttrSet(singularDatasourceName, "cluster_id"),
81+
82+
resource.TestCheckResourceAttr(singularDatasourceName, "status", "WAITING"),
83+
resource.TestCheckResourceAttr(singularDatasourceName, "status_details", "NEW_CREDENTIALS_ISSUED"),
84+
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_auto_completion_scheduled"),
85+
),
86+
},
87+
// complete rotation
88+
{
89+
Config: config +
90+
acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", acctest.Optional, acctest.Create, ContainerengineClusterRepresentationForCredentialRotation) +
91+
compartmentIdVariableStr + ContainerengineClusterResourceDependencies +
92+
acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster_complete_credential_rotation_management", "test_cluster_complete_credential_rotation_management", acctest.Required, acctest.Create, ContainerengineClusterCompleteCredentialRotationManagementRepresentation),
93+
},
94+
// verify complete rotation status
95+
{
96+
Config: config +
97+
acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", acctest.Optional, acctest.Create, ContainerengineClusterRepresentationForCredentialRotation) +
98+
compartmentIdVariableStr + ContainerengineClusterResourceDependencies +
99+
acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster_complete_credential_rotation_management", "test_cluster_complete_credential_rotation_management", acctest.Required, acctest.Create, ContainerengineClusterCompleteCredentialRotationManagementRepresentation) +
100+
acctest.GenerateDataSourceFromRepresentationMap("oci_containerengine_cluster_credential_rotation_status", "test_cluster_credential_rotation_status",
101+
acctest.Optional, acctest.Create, ContainerengineClusterCredentialRotationStatusSingularDataSourceRepresentation),
102+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
103+
resource.TestCheckResourceAttrSet(singularDatasourceName, "cluster_id"),
104+
105+
resource.TestCheckResourceAttr(singularDatasourceName, "status", "COMPLETED"),
106+
resource.TestCheckResourceAttr(singularDatasourceName, "status_details", "COMPLETED"),
107+
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_auto_completion_scheduled"),
108+
),
109+
},
110+
})
111+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright (c) 2017, 2023, 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+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
12+
"github.com/oracle/terraform-provider-oci/httpreplay"
13+
"github.com/oracle/terraform-provider-oci/internal/acctest"
14+
"github.com/oracle/terraform-provider-oci/internal/utils"
15+
)
16+
17+
var (
18+
ContainerengineClusterCredentialRotationStatusSingularDataSourceRepresentation = map[string]interface{}{
19+
"cluster_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_containerengine_cluster.test_cluster.id}`},
20+
}
21+
)
22+
23+
// issue-routing-tag: containerengine/default
24+
func TestContainerengineClusterCredentialRotationStatusResource_basic(t *testing.T) {
25+
httpreplay.SetScenario("TestContainerengineClusterCredentialRotationStatusResource_basic")
26+
defer httpreplay.SaveScenario()
27+
28+
config := acctest.ProviderTestConfig()
29+
30+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
31+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
32+
33+
resourceName := "oci_containerengine_cluster.test_cluster"
34+
singularDatasourceName := "data.oci_containerengine_cluster_credential_rotation_status.test_cluster_credential_rotation_status"
35+
36+
acctest.SaveConfigContent("", "", "", t)
37+
38+
acctest.ResourceTest(t, nil, []resource.TestStep{
39+
// create cluster
40+
{
41+
Config: config +
42+
acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", acctest.Optional, acctest.Create, ContainerengineClusterRepresentationForCredentialRotation) +
43+
compartmentIdVariableStr + ContainerengineClusterResourceDependencies,
44+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
45+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
46+
resource.TestCheckResourceAttrSet(resourceName, "kubernetes_version"),
47+
resource.TestCheckResourceAttr(resourceName, "name", "name"),
48+
resource.TestCheckResourceAttrSet(resourceName, "vcn_id"),
49+
resource.TestCheckResourceAttrSet(resourceName, "metadata.0.time_credential_expiration"),
50+
51+
func(s *terraform.State) (err error) {
52+
_, err = acctest.FromInstanceState(s, resourceName, "id")
53+
return err
54+
},
55+
),
56+
},
57+
58+
// start rotation
59+
{
60+
Config: config +
61+
acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", acctest.Optional, acctest.Create, ContainerengineClusterRepresentationForCredentialRotation) +
62+
compartmentIdVariableStr + ContainerengineClusterResourceDependencies +
63+
acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster_start_credential_rotation_management", "test_cluster_start_credential_rotation_management", acctest.Required, acctest.Create, ContainerengineClusterStartCredentialRotationManagementRepresentation),
64+
},
65+
66+
// verify rotation status
67+
{
68+
Config: config +
69+
acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", acctest.Optional, acctest.Create, ContainerengineClusterRepresentationForCredentialRotation) +
70+
compartmentIdVariableStr + ContainerengineClusterResourceDependencies +
71+
acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster_start_credential_rotation_management", "test_cluster_start_credential_rotation_management", acctest.Required, acctest.Create, ContainerengineClusterStartCredentialRotationManagementRepresentation) +
72+
acctest.GenerateDataSourceFromRepresentationMap("oci_containerengine_cluster_credential_rotation_status", "test_cluster_credential_rotation_status",
73+
acctest.Optional, acctest.Create, ContainerengineClusterCredentialRotationStatusSingularDataSourceRepresentation),
74+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
75+
resource.TestCheckResourceAttrSet(singularDatasourceName, "cluster_id"),
76+
77+
resource.TestCheckResourceAttr(singularDatasourceName, "status", "WAITING"),
78+
resource.TestCheckResourceAttr(singularDatasourceName, "status_details", "NEW_CREDENTIALS_ISSUED"),
79+
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_auto_completion_scheduled"),
80+
),
81+
},
82+
})
83+
}

0 commit comments

Comments
 (0)