Skip to content

Commit 826c532

Browse files
jotruonNagendraNigade
authored andcommitted
Added - Support for container engine boot volume encryption
1 parent 307d5f0 commit 826c532

File tree

8 files changed

+283
-7
lines changed

8 files changed

+283
-7
lines changed
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
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 "kms_vault_id" {
20+
}
21+
22+
variable "region" {
23+
default = "us-ashburn-1"
24+
}
25+
26+
# Provide the SSH public key to be set on each node in the node pool on launch.
27+
variable "node_pool_ssh_public_key" {
28+
default = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDOuBJgh6lTmQvQJ4BA3RCJdSmxRtmiXAQEEIP68/G4gF3XuZdKEYTFeputacmRq9yO5ZnNXgO9akdUgePpf8+CfFtveQxmN5xo3HVCDKxu/70lbMgeu7+wJzrMOlzj+a4zNq2j0Ww2VWMsisJ6eV3bJTnO/9VLGCOC8M9noaOlcKcLgIYy4aDM724MxFX2lgn7o6rVADHRxkvLEXPVqYT4syvYw+8OVSnNgE4MJLxaw8/2K0qp19YlQyiriIXfQpci3ThxwLjymYRPj+kjU1xIxv6qbFQzHR7ds0pSWp1U06cIoKPfCazU9hGWW8yIe/vzfTbWrt2DK6pLwBn/G0x3 sample"
29+
}
30+
31+
variable "node_pool_node_config_details_is_pv_encryption_in_transit_enabled" {
32+
default = true
33+
}
34+
35+
variable "node_pool_node_config_details_size" {
36+
default = 1
37+
}
38+
39+
provider "oci" {
40+
region = var.region
41+
tenancy_ocid = var.tenancy_ocid
42+
user_ocid = var.user_ocid
43+
fingerprint = var.fingerprint
44+
private_key_path = var.private_key_path
45+
}
46+
47+
data "oci_identity_availability_domain" "ad1" {
48+
compartment_id = var.tenancy_ocid
49+
ad_number = 1
50+
}
51+
52+
data "oci_identity_availability_domain" "ad2" {
53+
compartment_id = var.tenancy_ocid
54+
ad_number = 2
55+
}
56+
57+
resource "oci_kms_vault" "test_vault" {
58+
#Required
59+
compartment_id = var.compartment_ocid
60+
display_name = "tf_test"
61+
vault_type = "DEFAULT"
62+
}
63+
64+
resource "oci_kms_key" "test_key" {
65+
#Required
66+
compartment_id = var.compartment_ocid
67+
display_name = "tf-test-key"
68+
key_shape {
69+
#Required
70+
algorithm = "AES"
71+
length = 32
72+
}
73+
management_endpoint = oci_kms_vault.test_vault.management_endpoint
74+
}
75+
76+
resource "oci_core_vcn" "test_vcn" {
77+
cidr_block = "10.0.0.0/16"
78+
compartment_id = var.compartment_ocid
79+
display_name = "tfVcnForClusters"
80+
}
81+
82+
resource "oci_core_internet_gateway" "test_ig" {
83+
compartment_id = var.compartment_ocid
84+
display_name = "tfClusterInternetGateway"
85+
vcn_id = oci_core_vcn.test_vcn.id
86+
}
87+
88+
resource "oci_core_route_table" "test_route_table" {
89+
compartment_id = var.compartment_ocid
90+
vcn_id = oci_core_vcn.test_vcn.id
91+
display_name = "tfClustersRouteTable"
92+
93+
route_rules {
94+
destination = "0.0.0.0/0"
95+
destination_type = "CIDR_BLOCK"
96+
network_entity_id = oci_core_internet_gateway.test_ig.id
97+
}
98+
}
99+
100+
resource "oci_core_subnet" "nodePool_Subnet_1" {
101+
#Required
102+
availability_domain = data.oci_identity_availability_domain.ad1.name
103+
cidr_block = "10.0.22.0/24"
104+
compartment_id = var.compartment_ocid
105+
vcn_id = oci_core_vcn.test_vcn.id
106+
107+
# Provider code tries to maintain compatibility with old versions.
108+
security_list_ids = [oci_core_vcn.test_vcn.default_security_list_id]
109+
display_name = "tfSubNet1ForNodePool"
110+
route_table_id = oci_core_route_table.test_route_table.id
111+
}
112+
113+
resource "oci_core_subnet" "clusterSubnet_1" {
114+
#Required
115+
availability_domain = data.oci_identity_availability_domain.ad1.name
116+
cidr_block = "10.0.20.0/24"
117+
compartment_id = var.compartment_ocid
118+
vcn_id = oci_core_vcn.test_vcn.id
119+
120+
# Provider code tries to maintain compatibility with old versions.
121+
security_list_ids = [oci_core_vcn.test_vcn.default_security_list_id]
122+
display_name = "tfSubNet1ForClusters"
123+
route_table_id = oci_core_route_table.test_route_table.id
124+
}
125+
126+
resource "oci_core_subnet" "clusterSubnet_2" {
127+
#Required
128+
availability_domain = data.oci_identity_availability_domain.ad2.name
129+
cidr_block = "10.0.21.0/24"
130+
compartment_id = var.compartment_ocid
131+
vcn_id = oci_core_vcn.test_vcn.id
132+
display_name = "tfSubNet1ForClusters"
133+
134+
# Provider code tries to maintain compatibility with old versions.
135+
security_list_ids = [oci_core_vcn.test_vcn.default_security_list_id]
136+
route_table_id = oci_core_route_table.test_route_table.id
137+
}
138+
139+
resource "oci_containerengine_cluster" "test_cluster" {
140+
#Required
141+
compartment_id = var.compartment_ocid
142+
kubernetes_version = "v1.20.11"
143+
name = "tfTestCluster"
144+
vcn_id = oci_core_vcn.test_vcn.id
145+
146+
#Optional
147+
options {
148+
service_lb_subnet_ids = [oci_core_subnet.clusterSubnet_1.id, oci_core_subnet.clusterSubnet_2.id]
149+
150+
#Optional
151+
add_ons {
152+
#Optional
153+
is_kubernetes_dashboard_enabled = "true"
154+
is_tiller_enabled = "true"
155+
}
156+
157+
admission_controller_options {
158+
#Optional
159+
is_pod_security_policy_enabled = true
160+
}
161+
162+
kubernetes_network_config {
163+
#Optional
164+
pods_cidr = "10.1.0.0/16"
165+
services_cidr = "10.2.0.0/16"
166+
}
167+
}
168+
}
169+
170+
resource "oci_containerengine_node_pool" "test_node_pool" {
171+
#Required
172+
cluster_id = oci_containerengine_cluster.test_cluster.id
173+
compartment_id = var.compartment_ocid
174+
kubernetes_version = "v1.20.11"
175+
name = "tfPool"
176+
node_shape = "VM.Standard2.1"
177+
178+
#Optional
179+
initial_node_labels {
180+
#Optional
181+
key = "key"
182+
value = "value"
183+
}
184+
185+
node_source_details {
186+
#Required
187+
image_id = local.image_id
188+
source_type = "IMAGE"
189+
}
190+
191+
node_config_details {
192+
#Required
193+
placement_configs {
194+
#Required
195+
availability_domain = data.oci_identity_availability_domain.ad1.name
196+
subnet_id = oci_core_subnet.nodePool_Subnet_1.id
197+
}
198+
size = var.node_pool_node_config_details_size
199+
200+
#Optional
201+
is_pv_encryption_in_transit_enabled = var.node_pool_node_config_details_is_pv_encryption_in_transit_enabled
202+
kms_key_id = oci_kms_key.test_key.id
203+
}
204+
205+
ssh_public_key = var.node_pool_ssh_public_key
206+
}
207+
208+
output "node_pool" {
209+
value = {
210+
id = oci_containerengine_node_pool.test_node_pool.id
211+
kubernetes_version = oci_containerengine_node_pool.test_node_pool.kubernetes_version
212+
name = oci_containerengine_node_pool.test_node_pool.name
213+
subnet_ids = oci_containerengine_node_pool.test_node_pool.subnet_ids
214+
}
215+
}
216+
217+
data "oci_containerengine_node_pool_option" "test_node_pool_option" {
218+
node_pool_option_id = "all"
219+
}
220+
221+
data "oci_core_images" "shape_specific_images" {
222+
#Required
223+
compartment_id = var.tenancy_ocid
224+
shape = "VM.Standard2.1"
225+
}
226+
227+
locals {
228+
all_images = "${data.oci_core_images.shape_specific_images.images}"
229+
all_sources = "${data.oci_containerengine_node_pool_option.test_node_pool_option.sources}"
230+
231+
compartment_images = [for image in local.all_images : image.id if length(regexall("Oracle-Linux-[0-9]*.[0-9]*-20[0-9]*",image.display_name)) > 0 ]
232+
233+
oracle_linux_images = [for source in local.all_sources : source.image_id if length(regexall("Oracle-Linux-[0-9]*.[0-9]*-20[0-9]*",source.source_name)) > 0]
234+
235+
image_id = tolist(setintersection( toset(local.compartment_images), toset(local.oracle_linux_images)))[0]
236+
237+
}

internal/integrationtest/containerengine_node_pool_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ var (
7272
acctest.GenerateResourceFromRepresentationMap("oci_core_network_security_group", "test_network_security_group", acctest.Required, acctest.Create, networkSecurityGroupRepresentation) +
7373
acctest.GenerateResourceFromRepresentationMap("oci_core_vcn", "test_vcn", acctest.Required, acctest.Create, acctest.RepresentationCopyWithNewProperties(vcnRepresentation, map[string]interface{}{
7474
"dns_label": acctest.Representation{RepType: acctest.Required, Create: `dnslabel`},
75-
}))
75+
})) +
76+
KeyResourceDependencyConfig
7677
)
7778

7879
// issue-routing-tag: containerengine/default

internal/service/containerengine/containerengine_node_pool_resource.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ func ContainerengineNodePoolResource() *schema.Resource {
130130
},
131131

132132
// Optional
133+
"is_pv_encryption_in_transit_enabled": {
134+
Type: schema.TypeBool,
135+
Optional: true,
136+
Computed: true,
137+
},
138+
"kms_key_id": {
139+
Type: schema.TypeString,
140+
Optional: true,
141+
Computed: true,
142+
},
133143
"nsg_ids": {
134144
Type: schema.TypeSet,
135145
Optional: true,
@@ -941,6 +951,16 @@ func (s *ContainerengineNodePoolResourceCrud) SetData() error {
941951
func (s *ContainerengineNodePoolResourceCrud) mapToCreateNodePoolNodeConfigDetails(fieldKeyFormat string) (oci_containerengine.CreateNodePoolNodeConfigDetails, error) {
942952
result := oci_containerengine.CreateNodePoolNodeConfigDetails{}
943953

954+
if isPvEncryptionInTransitEnabled, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "is_pv_encryption_in_transit_enabled")); ok {
955+
tmp := isPvEncryptionInTransitEnabled.(bool)
956+
result.IsPvEncryptionInTransitEnabled = &tmp
957+
}
958+
959+
if kmsKeyId, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "kms_key_id")); ok {
960+
tmp := kmsKeyId.(string)
961+
result.KmsKeyId = &tmp
962+
}
963+
944964
if nsgIds, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "nsg_ids")); ok {
945965
set := nsgIds.(*schema.Set)
946966
interfaces := set.List()
@@ -984,6 +1004,14 @@ func (s *ContainerengineNodePoolResourceCrud) mapToCreateNodePoolNodeConfigDetai
9841004
func NodePoolNodeConfigDetailsToMap(obj *oci_containerengine.NodePoolNodeConfigDetails, datasource bool) map[string]interface{} {
9851005
result := map[string]interface{}{}
9861006

1007+
if obj.IsPvEncryptionInTransitEnabled != nil {
1008+
result["is_pv_encryption_in_transit_enabled"] = bool(*obj.IsPvEncryptionInTransitEnabled)
1009+
}
1010+
1011+
if obj.KmsKeyId != nil {
1012+
result["kms_key_id"] = string(*obj.KmsKeyId)
1013+
}
1014+
9871015
nsgIds := []interface{}{}
9881016
for _, item := range obj.NsgIds {
9891017
nsgIds = append(nsgIds, item)

website/docs/d/containerengine_clusters.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ The following attributes are exported:
8080
* `admission_controller_options` - Configurable cluster admission controllers
8181
* `is_pod_security_policy_enabled` - Whether or not to enable the Pod Security Policy admission controller.
8282
* `kubernetes_network_config` - Network configuration for Kubernetes.
83-
* `pods_cidr` - The CIDR block for Kubernetes pods.
84-
* `services_cidr` - The CIDR block for Kubernetes services.
83+
* `pods_cidr` - The CIDR block for Kubernetes pods. Optional, defaults to 10.244.0.0/16.
84+
* `services_cidr` - The CIDR block for Kubernetes services. Optional, defaults to 10.96.0.0/16.
8585
* `service_lb_subnet_ids` - The OCIDs of the subnets used for Kubernetes services load balancers.
8686
* `state` - The state of the cluster masters.
8787
* `vcn_id` - The OCID of the virtual cloud network (VCN) in which the cluster exists.

website/docs/d/containerengine_node_pool.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ The following attributes are exported:
4141
* `kubernetes_version` - The version of Kubernetes running on the nodes in the node pool.
4242
* `name` - The name of the node pool.
4343
* `node_config_details` - The configuration of nodes in the node pool.
44+
* `is_pv_encryption_in_transit_enabled` - Whether to enable in-transit encryption for the data volume's paravirtualized attachment. This field applies to both block volumes and boot volumes. The default value is false.
45+
* `kms_key_id` - The OCID of the Key Management Service key assigned to the boot volume.
4446
* `nsg_ids` - The OCIDs of the Network Security Group(s) to associate nodes for this node pool with. For more information about NSGs, see [NetworkSecurityGroup](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/NetworkSecurityGroup/).
4547
* `placement_configs` - The placement configurations for the node pool. Provide one placement configuration for each availability domain in which you intend to launch a node.
4648

website/docs/d/containerengine_node_pools.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ The following attributes are exported:
5353
* `kubernetes_version` - The version of Kubernetes running on the nodes in the node pool.
5454
* `name` - The name of the node pool.
5555
* `node_config_details` - The configuration of nodes in the node pool.
56+
* `is_pv_encryption_in_transit_enabled` - Whether to enable in-transit encryption for the data volume's paravirtualized attachment. This field applies to both block volumes and boot volumes. The default value is false.
57+
* `kms_key_id` - The OCID of the Key Management Service key assigned to the boot volume.
5658
* `nsg_ids` - The OCIDs of the Network Security Group(s) to associate nodes for this node pool with. For more information about NSGs, see [NetworkSecurityGroup](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/NetworkSecurityGroup/).
5759
* `placement_configs` - The placement configurations for the node pool. Provide one placement configuration for each availability domain in which you intend to launch a node.
5860

website/docs/r/containerengine_cluster.html.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ The following arguments are supported:
8989
* `admission_controller_options` - (Optional) (Updatable) Configurable cluster admission controllers
9090
* `is_pod_security_policy_enabled` - (Optional) (Updatable) Whether or not to enable the Pod Security Policy admission controller.
9191
* `kubernetes_network_config` - (Optional) Network configuration for Kubernetes.
92-
* `pods_cidr` - (Optional) The CIDR block for Kubernetes pods.
93-
* `services_cidr` - (Optional) The CIDR block for Kubernetes services.
92+
* `pods_cidr` - (Optional) The CIDR block for Kubernetes pods. Optional, defaults to 10.244.0.0/16.
93+
* `services_cidr` - (Optional) The CIDR block for Kubernetes services. Optional, defaults to 10.96.0.0/16.
9494
* `service_lb_subnet_ids` - (Optional) The OCIDs of the subnets used for Kubernetes services load balancers.
9595
* `vcn_id` - (Required) The OCID of the virtual cloud network (VCN) in which to create the cluster.
9696

@@ -138,8 +138,8 @@ The following attributes are exported:
138138
* `admission_controller_options` - Configurable cluster admission controllers
139139
* `is_pod_security_policy_enabled` - Whether or not to enable the Pod Security Policy admission controller.
140140
* `kubernetes_network_config` - Network configuration for Kubernetes.
141-
* `pods_cidr` - The CIDR block for Kubernetes pods.
142-
* `services_cidr` - The CIDR block for Kubernetes services.
141+
* `pods_cidr` - The CIDR block for Kubernetes pods. Optional, defaults to 10.244.0.0/16.
142+
* `services_cidr` - The CIDR block for Kubernetes services. Optional, defaults to 10.96.0.0/16.
143143
* `service_lb_subnet_ids` - The OCIDs of the subnets used for Kubernetes services load balancers.
144144
* `state` - The state of the cluster masters.
145145
* `vcn_id` - The OCID of the virtual cloud network (VCN) in which the cluster exists.

website/docs/r/containerengine_node_pool.html.markdown

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ resource "oci_containerengine_node_pool" "test_node_pool" {
4141
size = var.node_pool_node_config_details_size
4242
4343
#Optional
44+
is_pv_encryption_in_transit_enabled = var.node_pool_node_config_details_is_pv_encryption_in_transit_enabled
45+
kms_key_id = oci_kms_key.test_key.id
4446
nsg_ids = var.node_pool_node_config_details_nsg_ids
4547
}
4648
node_image_name = oci_core_image.test_image.name
@@ -76,6 +78,8 @@ The following arguments are supported:
7678
* `kubernetes_version` - (Required) (Updatable) The version of Kubernetes to install on the nodes in the node pool.
7779
* `name` - (Required) (Updatable) The name of the node pool. Avoid entering confidential information.
7880
* `node_config_details` - (Optional) (Updatable) The configuration of nodes in the node pool. Exactly one of the subnetIds or nodeConfigDetails properties must be specified.
81+
* `is_pv_encryption_in_transit_enabled` - (Optional) (Updatable) Whether to enable in-transit encryption for the data volume's paravirtualized attachment. This field applies to both block volumes and boot volumes. The default value is false.
82+
* `kms_key_id` - (Optional) (Updatable) The OCID of the Key Management Service key assigned to the boot volume.
7983
* `nsg_ids` - (Optional) (Updatable) The OCIDs of the Network Security Group(s) to associate nodes for this node pool with. For more information about NSGs, see [NetworkSecurityGroup](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/NetworkSecurityGroup/).
8084
* `placement_configs` - (Required) (Updatable) The placement configurations for the node pool. Provide one placement configuration for each availability domain in which you intend to launch a node.
8185

@@ -115,6 +119,8 @@ The following attributes are exported:
115119
* `kubernetes_version` - The version of Kubernetes running on the nodes in the node pool.
116120
* `name` - The name of the node pool.
117121
* `node_config_details` - The configuration of nodes in the node pool.
122+
* `is_pv_encryption_in_transit_enabled` - Whether to enable in-transit encryption for the data volume's paravirtualized attachment. This field applies to both block volumes and boot volumes. The default value is false.
123+
* `kms_key_id` - The OCID of the Key Management Service key assigned to the boot volume.
118124
* `nsg_ids` - The OCIDs of the Network Security Group(s) to associate nodes for this node pool with. For more information about NSGs, see [NetworkSecurityGroup](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/NetworkSecurityGroup/).
119125
* `placement_configs` - The placement configurations for the node pool. Provide one placement configuration for each availability domain in which you intend to launch a node.
120126

0 commit comments

Comments
 (0)