Skip to content

Commit 08201ef

Browse files
Implement OKE changes to support Native VCN Clusters
1 parent e7ef971 commit 08201ef

17 files changed

+274
-28
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Added
44
- Support for updating instance type in `oci_oce_oce_instance`
5+
- Support for private native vcn clusters to `container_engine`
56

67
## 4.17.0 (March 10, 2021)
78

examples/container_engine/regional_subnet/cluster.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ resource "oci_containerengine_cluster" "test_cluster" {
99
vcn_id = oci_core_vcn.test_vcn.id
1010

1111
#Optional
12+
endpoint_config {
13+
subnet_id = oci_core_subnet.cluster_regional_subnet.id
14+
is_public_ip_enabled = "true"
15+
nsg_ids = [oci_core_network_security_group.test_nsg.id]
16+
}
17+
1218
options {
1319
service_lb_subnet_ids = [oci_core_subnet.clusterSubnet_1.id, oci_core_subnet.clusterSubnet_2.id]
1420

examples/container_engine/regional_subnet/networking.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ resource "oci_core_vcn" "test_vcn" {
77
display_name = "tfVcnForClusters"
88
}
99

10+
resource "oci_core_network_security_group" "test_nsg" {
11+
compartment_id = var.compartment_ocid
12+
display_name = "tfNsgForClusters"
13+
vcn_id = oci_core_vcn.test_vcn.id
14+
}
15+
1016
resource "oci_core_internet_gateway" "test_ig" {
1117
compartment_id = var.compartment_ocid
1218
display_name = "tfClusterInternetGateway"
@@ -51,6 +57,18 @@ resource "oci_core_subnet" "clusterSubnet_2" {
5157
route_table_id = oci_core_route_table.test_route_table.id
5258
}
5359

60+
resource "oci_core_subnet" "cluster_regional_subnet" {
61+
#Required
62+
cidr_block = "10.0.26.0/24"
63+
compartment_id = var.compartment_ocid
64+
vcn_id = oci_core_vcn.test_vcn.id
65+
66+
# Provider code tries to maintain compatibility with old versions.
67+
security_list_ids = [oci_core_vcn.test_vcn.default_security_list_id]
68+
display_name = "clusterRegionalSubnet"
69+
route_table_id = oci_core_route_table.test_route_table.id
70+
}
71+
5472
resource "oci_core_subnet" "node_pool_regional_subnet_1" {
5573
#Required
5674
cidr_block = "10.0.24.0/24"

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ require (
1414
)
1515

1616
// Uncomment this line to get OCI Go SDK from local source instead of github
17-
//replace github.com/oracle/oci-go-sdk => ../../oracle/oci-go-sdk
17+
// replace github.com/oracle/oci-go-sdk/v35 => ../../oracle/oci-go-sdk

oci/containerengine_cluster_kube_config_data_source.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ func ContainerengineClusterKubeConfigDataSource() *schema.Resource {
2424
Type: schema.TypeString,
2525
Required: true,
2626
},
27+
"endpoint": {
28+
Type: schema.TypeString,
29+
Optional: true,
30+
},
2731
"expiration": {
2832
Type: schema.TypeInt,
2933
Optional: true,
@@ -67,6 +71,10 @@ func (s *ContainerengineClusterKubeConfigDataSourceCrud) Get() error {
6771
request.ClusterId = &tmp
6872
}
6973

74+
if endpoint, ok := s.D.GetOkExists("endpoint"); ok {
75+
request.Endpoint = oci_containerengine.CreateClusterKubeconfigContentDetailsEndpointEnum(endpoint.(string))
76+
}
77+
7078
if expiration, ok := s.D.GetOkExists("expiration"); ok {
7179
tmp := expiration.(int)
7280
request.Expiration = &tmp

oci/containerengine_cluster_kube_config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
var (
1717
clusterKubeConfigSingularDataSourceRepresentation = map[string]interface{}{
1818
"cluster_id": Representation{repType: Required, create: `${oci_containerengine_cluster.test_cluster.id}`},
19+
"endpoint": Representation{repType: Optional, create: `LEGACY_KUBERNETES`},
1920
"token_version": Representation{repType: Optional, create: `2.0.0`},
2021
}
2122

@@ -56,6 +57,7 @@ func TestContainerengineClusterKubeConfigResource_basic(t *testing.T) {
5657
compartmentIdVariableStr + ClusterKubeConfigResourceConfig,
5758
Check: resource.ComposeAggregateTestCheckFunc(
5859
resource.TestCheckResourceAttrSet(singularDatasourceName, "cluster_id"),
60+
resource.TestCheckResourceAttr(singularDatasourceName, "endpoint", "LEGACY_KUBERNETES"),
5961
resource.TestCheckResourceAttr(singularDatasourceName, "token_version", "2.0.0"),
6062
resource.TestCheckResourceAttrSet(singularDatasourceName, "content"),
6163
),

oci/containerengine_cluster_resource.go

Lines changed: 171 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,39 @@ func ContainerengineClusterResource() *schema.Resource {
5959
},
6060

6161
// Optional
62+
"endpoint_config": {
63+
Type: schema.TypeList,
64+
Optional: true,
65+
MaxItems: 1,
66+
MinItems: 1,
67+
Elem: &schema.Resource{
68+
Schema: map[string]*schema.Schema{
69+
// Required
70+
"subnet_id": {
71+
Type: schema.TypeString,
72+
Required: true,
73+
ForceNew: true,
74+
},
75+
76+
// Optional
77+
"is_public_ip_enabled": {
78+
Type: schema.TypeBool,
79+
Optional: true,
80+
Computed: true,
81+
},
82+
"nsg_ids": {
83+
Type: schema.TypeSet,
84+
Optional: true,
85+
Set: literalTypeHashCodeForSets,
86+
Elem: &schema.Schema{
87+
Type: schema.TypeString,
88+
},
89+
},
90+
91+
// Computed
92+
},
93+
},
94+
},
6295
"kms_key_id": {
6396
Type: schema.TypeString,
6497
Optional: true,
@@ -194,6 +227,14 @@ func ContainerengineClusterResource() *schema.Resource {
194227
Type: schema.TypeString,
195228
Computed: true,
196229
},
230+
"private_endpoint": {
231+
Type: schema.TypeString,
232+
Computed: true,
233+
},
234+
"public_endpoint": {
235+
Type: schema.TypeString,
236+
Computed: true,
237+
},
197238
},
198239
},
199240
},
@@ -336,6 +377,17 @@ func (s *ContainerengineClusterResourceCrud) Create() error {
336377
request.CompartmentId = &tmp
337378
}
338379

380+
if endpointConfig, ok := s.D.GetOkExists("endpoint_config"); ok {
381+
if tmpList := endpointConfig.([]interface{}); len(tmpList) > 0 {
382+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "endpoint_config", 0)
383+
tmp, err := s.mapToCreateClusterEndpointConfigDetails(fieldKeyFormat)
384+
if err != nil {
385+
return err
386+
}
387+
request.EndpointConfig = &tmp
388+
}
389+
}
390+
339391
if kmsKeyId, ok := s.D.GetOkExists("kms_key_id"); ok {
340392
tmp := kmsKeyId.(string)
341393
request.KmsKeyId = &tmp
@@ -525,10 +577,16 @@ func (s *ContainerengineClusterResourceCrud) Get() error {
525577
}
526578

527579
func (s *ContainerengineClusterResourceCrud) Update() error {
528-
request := oci_containerengine.UpdateClusterRequest{}
580+
clusterID := s.D.Id()
581+
if endpointConfig, ok := s.D.GetOkExists("endpoint_config"); ok && s.D.HasChange("endpoint_config") {
582+
err := s.updateClusterEndpointConfig(clusterID, endpointConfig)
583+
if err != nil {
584+
return err
585+
}
586+
}
529587

530-
tmp := s.D.Id()
531-
request.ClusterId = &tmp
588+
request := oci_containerengine.UpdateClusterRequest{}
589+
request.ClusterId = &clusterID
532590

533591
if kubernetesVersion, ok := s.D.GetOkExists("kubernetes_version"); ok {
534592
tmp := kubernetesVersion.(string)
@@ -561,6 +619,26 @@ func (s *ContainerengineClusterResourceCrud) Update() error {
561619
workId := response.OpcWorkRequestId
562620
return s.getClusterFromWorkRequest(workId, getRetryPolicy(s.DisableNotFoundRetries, "containerengine"), oci_containerengine.WorkRequestResourceActionTypeUpdated, s.D.Timeout(schema.TimeoutUpdate))
563621
}
622+
func (s *ContainerengineClusterResourceCrud) updateClusterEndpointConfig(clusterID string, endpointConfig interface{}) error {
623+
request := oci_containerengine.UpdateClusterEndpointConfigRequest{}
624+
request.ClusterId = &clusterID
625+
if tmpList := endpointConfig.([]interface{}); len(tmpList) > 0 {
626+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "endpoint_config", 0)
627+
tmp, err := s.mapToUpdateClusterEndpointConfigDetails(fieldKeyFormat)
628+
if err != nil {
629+
return err
630+
}
631+
request.UpdateClusterEndpointConfigDetails = tmp
632+
}
633+
634+
response, err := s.Client.UpdateClusterEndpointConfig(context.Background(), request)
635+
if err != nil {
636+
return err
637+
}
638+
639+
workID := response.OpcWorkRequestId
640+
return s.getClusterFromWorkRequest(workID, getRetryPolicy(s.DisableNotFoundRetries, "containerengine"), oci_containerengine.WorkRequestResourceActionTypeUpdated, s.D.Timeout(schema.TimeoutUpdate))
641+
}
564642

565643
func (s *ContainerengineClusterResourceCrud) Delete() error {
566644
request := oci_containerengine.DeleteClusterRequest{}
@@ -589,6 +667,12 @@ func (s *ContainerengineClusterResourceCrud) SetData() error {
589667
s.D.Set("compartment_id", *s.Res.CompartmentId)
590668
}
591669

670+
if s.Res.EndpointConfig != nil {
671+
s.D.Set("endpoint_config", []interface{}{ClusterEndpointConfigToMap(s.Res.EndpointConfig, false)})
672+
} else {
673+
s.D.Set("endpoint_config", nil)
674+
}
675+
592676
if s.Res.Endpoints != nil {
593677
s.D.Set("endpoints", []interface{}{ClusterEndpointsToMap(s.Res.Endpoints)})
594678
} else {
@@ -762,6 +846,14 @@ func ClusterEndpointsToMap(obj *oci_containerengine.ClusterEndpoints) map[string
762846
result["kubernetes"] = string(*obj.Kubernetes)
763847
}
764848

849+
if obj.PrivateEndpoint != nil {
850+
result["private_endpoint"] = string(*obj.PrivateEndpoint)
851+
}
852+
853+
if obj.PublicEndpoint != nil {
854+
result["public_endpoint"] = string(*obj.PublicEndpoint)
855+
}
856+
765857
return result
766858
}
767859

@@ -807,6 +899,82 @@ func ClusterMetadataToMap(obj *oci_containerengine.ClusterMetadata) map[string]i
807899
return result
808900
}
809901

902+
func (s *ContainerengineClusterResourceCrud) mapToUpdateClusterEndpointConfigDetails(fieldKeyFormat string) (oci_containerengine.UpdateClusterEndpointConfigDetails, error) {
903+
result := oci_containerengine.UpdateClusterEndpointConfigDetails{}
904+
if isPublicIpEnabled, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "is_public_ip_enabled")); ok {
905+
tmp := isPublicIpEnabled.(bool)
906+
result.IsPublicIpEnabled = &tmp
907+
}
908+
if nsgIds, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "nsg_ids")); ok {
909+
set := nsgIds.(*schema.Set)
910+
interfaces := set.List()
911+
tmp := make([]string, len(interfaces))
912+
for i := range interfaces {
913+
if interfaces[i] != nil {
914+
tmp[i] = interfaces[i].(string)
915+
}
916+
}
917+
if len(tmp) != 0 || s.D.HasChange(fmt.Sprintf(fieldKeyFormat, "nsg_ids")) {
918+
result.NsgIds = tmp
919+
}
920+
}
921+
return result, nil
922+
}
923+
924+
func (s *ContainerengineClusterResourceCrud) mapToCreateClusterEndpointConfigDetails(fieldKeyFormat string) (oci_containerengine.CreateClusterEndpointConfigDetails, error) {
925+
result := oci_containerengine.CreateClusterEndpointConfigDetails{}
926+
927+
if isPublicIpEnabled, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "is_public_ip_enabled")); ok {
928+
tmp := isPublicIpEnabled.(bool)
929+
result.IsPublicIpEnabled = &tmp
930+
}
931+
932+
if nsgIds, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "nsg_ids")); ok {
933+
set := nsgIds.(*schema.Set)
934+
interfaces := set.List()
935+
tmp := make([]string, len(interfaces))
936+
for i := range interfaces {
937+
if interfaces[i] != nil {
938+
tmp[i] = interfaces[i].(string)
939+
}
940+
}
941+
if len(tmp) != 0 || s.D.HasChange(fmt.Sprintf(fieldKeyFormat, "nsg_ids")) {
942+
result.NsgIds = tmp
943+
}
944+
}
945+
946+
if subnetId, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "subnet_id")); ok {
947+
tmp := subnetId.(string)
948+
result.SubnetId = &tmp
949+
}
950+
951+
return result, nil
952+
}
953+
954+
func ClusterEndpointConfigToMap(obj *oci_containerengine.ClusterEndpointConfig, datasource bool) map[string]interface{} {
955+
result := map[string]interface{}{}
956+
957+
if obj.IsPublicIpEnabled != nil {
958+
result["is_public_ip_enabled"] = bool(*obj.IsPublicIpEnabled)
959+
}
960+
961+
nsgIds := []interface{}{}
962+
for _, item := range obj.NsgIds {
963+
nsgIds = append(nsgIds, item)
964+
}
965+
if datasource {
966+
result["nsg_ids"] = nsgIds
967+
} else {
968+
result["nsg_ids"] = schema.NewSet(literalTypeHashCodeForSets, nsgIds)
969+
}
970+
971+
if obj.SubnetId != nil {
972+
result["subnet_id"] = string(*obj.SubnetId)
973+
}
974+
975+
return result
976+
}
977+
810978
func (s *ContainerengineClusterResourceCrud) mapToKubernetesNetworkConfig(fieldKeyFormat string) (oci_containerengine.KubernetesNetworkConfig, error) {
811979
result := oci_containerengine.KubernetesNetworkConfig{}
812980

0 commit comments

Comments
 (0)