Skip to content

Commit eb32273

Browse files
abhilash-avkilokahn
authored andcommitted
Add support for node metadata in OKE NodePools
1 parent adf9377 commit eb32273

7 files changed

+80
-1
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 cloning of Autonomous Databases
5+
- Support for node metadata in container engine node pool
56

67
## 3.18.0 (March 13, 2019)
78

oci/containerengine_node_pool_data_source.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ func ContainerengineNodePoolDataSource() *schema.Resource {
6565
Type: schema.TypeString,
6666
Computed: true,
6767
},
68+
"node_metadata": {
69+
Type: schema.TypeMap,
70+
Computed: true,
71+
Elem: schema.TypeString,
72+
},
6873
"node_shape": {
6974
Type: schema.TypeString,
7075
Computed: true,
@@ -234,6 +239,8 @@ func (s *ContainerengineNodePoolDataSourceCrud) SetData() error {
234239
s.D.Set("node_image_name", *s.Res.NodeImageName)
235240
}
236241

242+
s.D.Set("node_metadata", s.Res.NodeMetadata)
243+
237244
if s.Res.NodeShape != nil {
238245
s.D.Set("node_shape", *s.Res.NodeShape)
239246
}

oci/containerengine_node_pool_resource.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ func ContainerengineNodePoolResource() *schema.Resource {
9999
},
100100
},
101101
},
102+
"node_metadata": {
103+
Type: schema.TypeMap,
104+
Optional: true,
105+
Computed: true,
106+
ForceNew: true,
107+
Elem: schema.TypeString,
108+
},
102109
"quantity_per_subnet": {
103110
Type: schema.TypeInt,
104111
Optional: true,
@@ -281,6 +288,10 @@ func (s *ContainerengineNodePoolResourceCrud) Create() error {
281288
request.NodeImageName = &tmp
282289
}
283290

291+
if nodeMetadata, ok := s.D.GetOkExists("node_metadata"); ok {
292+
request.NodeMetadata = objectMapToStringMap(nodeMetadata.(map[string]interface{}))
293+
}
294+
284295
if nodeShape, ok := s.D.GetOkExists("node_shape"); ok {
285296
tmp := nodeShape.(string)
286297
request.NodeShape = &tmp
@@ -510,6 +521,8 @@ func (s *ContainerengineNodePoolResourceCrud) SetData() error {
510521
s.D.Set("node_image_name", *s.Res.NodeImageName)
511522
}
512523

524+
s.D.Set("node_metadata", s.Res.NodeMetadata)
525+
513526
if s.Res.NodeShape != nil {
514527
s.D.Set("node_shape", *s.Res.NodeShape)
515528
}

oci/containerengine_node_pool_test.go

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ var (
5757
"node_shape": Representation{repType: Required, create: `VM.Standard2.1`},
5858
"subnet_ids": Representation{repType: Required, create: []string{`${oci_core_subnet.nodePool_Subnet_1.id}`, `${oci_core_subnet.nodePool_Subnet_2.id}`}},
5959
"initial_node_labels": RepresentationGroup{Optional, nodePoolInitialNodeLabelsRepresentation},
60+
"node_metadata": Representation{repType: Optional, create: map[string]string{"nodeMetadata": "nodeMetadata"}, update: map[string]string{"nodeMetadata2": "nodeMetadata2"}},
6061
"quantity_per_subnet": Representation{repType: Optional, create: `1`, update: `2`},
6162
"ssh_public_key": Representation{repType: Optional, create: `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDOuBJgh6lTmQvQJ4BA3RCJdSmxRtmiXAQEEIP68/G4gF3XuZdKEYTFeputacmRq9yO5ZnNXgO9akdUgePpf8+CfFtveQxmN5xo3HVCDKxu/70lbMgeu7+wJzrMOlzj+a4zNq2j0Ww2VWMsisJ6eV3bJTnO/9VLGCOC8M9noaOlcKcLgIYy4aDM724MxFX2lgn7o6rVADHRxkvLEXPVqYT4syvYw+8OVSnNgE4MJLxaw8/2K0qp19YlQyiriIXfQpci3ThxwLjymYRPj+kjU1xIxv6qbFQzHR7ds0pSWp1U06cIoKPfCazU9hGWW8yIe/vzfTbWrt2DK6pLwBn/G0x3 sample`},
6263
}
@@ -166,6 +167,7 @@ func TestContainerengineNodePoolResource_basic(t *testing.T) {
166167
resource.TestCheckResourceAttrSet(resourceName, "kubernetes_version"),
167168
resource.TestCheckResourceAttr(resourceName, "name", "name"),
168169
resource.TestCheckResourceAttr(resourceName, "node_image_name", "Oracle-Linux-7.4"),
170+
resource.TestCheckResourceAttr(resourceName, "node_metadata.%", "1"),
169171
resource.TestCheckResourceAttr(resourceName, "node_shape", "VM.Standard2.1"),
170172
resource.TestCheckResourceAttr(resourceName, "quantity_per_subnet", "1"),
171173
resource.TestCheckResourceAttr(resourceName, "ssh_public_key", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDOuBJgh6lTmQvQJ4BA3RCJdSmxRtmiXAQEEIP68/G4gF3XuZdKEYTFeputacmRq9yO5ZnNXgO9akdUgePpf8+CfFtveQxmN5xo3HVCDKxu/70lbMgeu7+wJzrMOlzj+a4zNq2j0Ww2VWMsisJ6eV3bJTnO/9VLGCOC8M9noaOlcKcLgIYy4aDM724MxFX2lgn7o6rVADHRxkvLEXPVqYT4syvYw+8OVSnNgE4MJLxaw8/2K0qp19YlQyiriIXfQpci3ThxwLjymYRPj+kjU1xIxv6qbFQzHR7ds0pSWp1U06cIoKPfCazU9hGWW8yIe/vzfTbWrt2DK6pLwBn/G0x3 sample"),
@@ -196,7 +198,7 @@ func TestContainerengineNodePoolResource_basic(t *testing.T) {
196198
// verify updates to updatable parameters
197199
{
198200
Config: config + compartmentIdVariableStr + NodePoolResourceDependencies +
199-
generateResourceFromRepresentationMap("oci_containerengine_node_pool", "test_node_pool", Optional, Update, nodePoolRepresentation) +
201+
generateResourceFromRepresentationMap("oci_containerengine_node_pool", "test_node_pool", Optional, Update, getUpdatedRepresentationCopy("node_metadata", Representation{repType: Optional, update: map[string]string{"nodeMetadata": "nodeMetadata"}}, nodePoolRepresentation)) +
200202
generateResourceFromRepresentationMap("oci_containerengine_node_pool", "test_node_pool_imageId", Optional, Update, nodePoolRepresentationForImageId),
201203
Check: resource.ComposeAggregateTestCheckFunc(
202204
//Asserting Resource created with Image Name
@@ -208,6 +210,7 @@ func TestContainerengineNodePoolResource_basic(t *testing.T) {
208210
resource.TestCheckResourceAttrSet(resourceName, "kubernetes_version"),
209211
resource.TestCheckResourceAttr(resourceName, "name", "name2"),
210212
resource.TestCheckResourceAttr(resourceName, "node_image_name", "Oracle-Linux-7.4"),
213+
resource.TestCheckResourceAttr(resourceName, "node_metadata.%", "1"),
211214
resource.TestCheckResourceAttr(resourceName, "node_shape", "VM.Standard2.1"),
212215
resource.TestCheckResourceAttr(resourceName, "quantity_per_subnet", "2"),
213216
resource.TestCheckResourceAttr(resourceName, "ssh_public_key", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDOuBJgh6lTmQvQJ4BA3RCJdSmxRtmiXAQEEIP68/G4gF3XuZdKEYTFeputacmRq9yO5ZnNXgO9akdUgePpf8+CfFtveQxmN5xo3HVCDKxu/70lbMgeu7+wJzrMOlzj+a4zNq2j0Ww2VWMsisJ6eV3bJTnO/9VLGCOC8M9noaOlcKcLgIYy4aDM724MxFX2lgn7o6rVADHRxkvLEXPVqYT4syvYw+8OVSnNgE4MJLxaw8/2K0qp19YlQyiriIXfQpci3ThxwLjymYRPj+kjU1xIxv6qbFQzHR7ds0pSWp1U06cIoKPfCazU9hGWW8yIe/vzfTbWrt2DK6pLwBn/G0x3 sample"),
@@ -241,6 +244,55 @@ func TestContainerengineNodePoolResource_basic(t *testing.T) {
241244
),
242245
},
243246

247+
// verify updates to node_metadata should create new resource
248+
{
249+
Config: config + compartmentIdVariableStr + NodePoolResourceDependencies +
250+
generateResourceFromRepresentationMap("oci_containerengine_node_pool", "test_node_pool", Optional, Update, nodePoolRepresentation) +
251+
generateResourceFromRepresentationMap("oci_containerengine_node_pool", "test_node_pool_imageId", Optional, Update, nodePoolRepresentationForImageId),
252+
Check: resource.ComposeAggregateTestCheckFunc(
253+
//Asserting Resource created with Image Name
254+
resource.TestCheckResourceAttrSet(resourceName, "cluster_id"),
255+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
256+
resource.TestCheckResourceAttr(resourceName, "initial_node_labels.#", "1"),
257+
resource.TestCheckResourceAttr(resourceName, "initial_node_labels.0.key", "key2"),
258+
resource.TestCheckResourceAttr(resourceName, "initial_node_labels.0.value", "value2"),
259+
resource.TestCheckResourceAttrSet(resourceName, "kubernetes_version"),
260+
resource.TestCheckResourceAttr(resourceName, "name", "name2"),
261+
resource.TestCheckResourceAttr(resourceName, "node_image_name", "Oracle-Linux-7.4"),
262+
resource.TestCheckResourceAttr(resourceName, "node_metadata.%", "1"),
263+
resource.TestCheckResourceAttr(resourceName, "node_shape", "VM.Standard2.1"),
264+
resource.TestCheckResourceAttr(resourceName, "quantity_per_subnet", "2"),
265+
resource.TestCheckResourceAttr(resourceName, "ssh_public_key", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDOuBJgh6lTmQvQJ4BA3RCJdSmxRtmiXAQEEIP68/G4gF3XuZdKEYTFeputacmRq9yO5ZnNXgO9akdUgePpf8+CfFtveQxmN5xo3HVCDKxu/70lbMgeu7+wJzrMOlzj+a4zNq2j0Ww2VWMsisJ6eV3bJTnO/9VLGCOC8M9noaOlcKcLgIYy4aDM724MxFX2lgn7o6rVADHRxkvLEXPVqYT4syvYw+8OVSnNgE4MJLxaw8/2K0qp19YlQyiriIXfQpci3ThxwLjymYRPj+kjU1xIxv6qbFQzHR7ds0pSWp1U06cIoKPfCazU9hGWW8yIe/vzfTbWrt2DK6pLwBn/G0x3 sample"),
266+
resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", "2"),
267+
//Asserting Resource created with Image Id
268+
resource.TestCheckResourceAttrSet(resourceNameForImageId, "cluster_id"),
269+
resource.TestCheckResourceAttr(resourceNameForImageId, "compartment_id", compartmentId),
270+
resource.TestCheckResourceAttr(resourceNameForImageId, "initial_node_labels.#", "1"),
271+
resource.TestCheckResourceAttr(resourceNameForImageId, "initial_node_labels.0.key", "key2"),
272+
resource.TestCheckResourceAttr(resourceNameForImageId, "initial_node_labels.0.value", "value2"),
273+
resource.TestCheckResourceAttrSet(resourceNameForImageId, "kubernetes_version"),
274+
resource.TestCheckResourceAttr(resourceNameForImageId, "name", "name2"),
275+
resource.TestCheckResourceAttrSet(resourceNameForImageId, "node_image_name"),
276+
resource.TestCheckResourceAttrSet(resourceNameForImageId, "node_image_id"),
277+
resource.TestCheckResourceAttr(resourceNameForImageId, "node_shape", "VM.Standard2.1"),
278+
resource.TestCheckResourceAttr(resourceNameForImageId, "quantity_per_subnet", "2"),
279+
resource.TestCheckResourceAttr(resourceNameForImageId, "ssh_public_key", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDOuBJgh6lTmQvQJ4BA3RCJdSmxRtmiXAQEEIP68/G4gF3XuZdKEYTFeputacmRq9yO5ZnNXgO9akdUgePpf8+CfFtveQxmN5xo3HVCDKxu/70lbMgeu7+wJzrMOlzj+a4zNq2j0Ww2VWMsisJ6eV3bJTnO/9VLGCOC8M9noaOlcKcLgIYy4aDM724MxFX2lgn7o6rVADHRxkvLEXPVqYT4syvYw+8OVSnNgE4MJLxaw8/2K0qp19YlQyiriIXfQpci3ThxwLjymYRPj+kjU1xIxv6qbFQzHR7ds0pSWp1U06cIoKPfCazU9hGWW8yIe/vzfTbWrt2DK6pLwBn/G0x3 sample"),
280+
resource.TestCheckResourceAttr(resourceNameForImageId, "subnet_ids.#", "2"),
281+
282+
func(s *terraform.State) (err error) {
283+
resId2, err = fromInstanceState(s, resourceName, "id")
284+
if resId == resId2 {
285+
return fmt.Errorf("Resource updated when it was supposed to be recreated.")
286+
}
287+
resId2CreatedWithImageId, err = fromInstanceState(s, resourceNameForImageId, "id")
288+
if resIdCreatedWithImageId != resId2CreatedWithImageId {
289+
return fmt.Errorf("Resource recreated when it was supposed to be updated.")
290+
}
291+
return err
292+
},
293+
),
294+
},
295+
244296
// verify datasource
245297
{
246298
Config: config +
@@ -308,6 +360,7 @@ func TestContainerengineNodePoolResource_basic(t *testing.T) {
308360
resource.TestCheckResourceAttrSet(singularDatasourceName, "kubernetes_version"),
309361
resource.TestCheckResourceAttr(singularDatasourceName, "name", "name2"),
310362
resource.TestCheckResourceAttr(singularDatasourceName, "node_image_name", "Oracle-Linux-7.4"),
363+
resource.TestCheckResourceAttr(singularDatasourceName, "node_metadata.%", "1"),
311364
resource.TestCheckResourceAttr(singularDatasourceName, "node_shape", "VM.Standard2.1"),
312365
resource.TestCheckResourceAttr(singularDatasourceName, "quantity_per_subnet", "2"),
313366
resource.TestCheckResourceAttr(singularDatasourceName, "ssh_public_key", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDOuBJgh6lTmQvQJ4BA3RCJdSmxRtmiXAQEEIP68/G4gF3XuZdKEYTFeputacmRq9yO5ZnNXgO9akdUgePpf8+CfFtveQxmN5xo3HVCDKxu/70lbMgeu7+wJzrMOlzj+a4zNq2j0Ww2VWMsisJ6eV3bJTnO/9VLGCOC8M9noaOlcKcLgIYy4aDM724MxFX2lgn7o6rVADHRxkvLEXPVqYT4syvYw+8OVSnNgE4MJLxaw8/2K0qp19YlQyiriIXfQpci3ThxwLjymYRPj+kjU1xIxv6qbFQzHR7ds0pSWp1U06cIoKPfCazU9hGWW8yIe/vzfTbWrt2DK6pLwBn/G0x3 sample"),

website/docs/d/containerengine_node_pool.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ The following attributes are exported:
4141
* `name` - The name of the node pool.
4242
* `node_image_id` - The OCID of the image running on the nodes in the node pool.
4343
* `node_image_name` - The name of the image running on the nodes in the node pool.
44+
* `node_metadata` - A list of key/value pairs to add to each underlyingOracle Cloud Infrastructure instance in the node pool.
4445
* `node_shape` - The name of the node shape of the nodes in the node pool.
4546
* `nodes` - The nodes in the node pool.
4647
* `availability_domain` - The name of the availability domain in which this node is placed.

website/docs/d/containerengine_node_pools.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ The following attributes are exported:
5353
* `name` - The name of the node pool.
5454
* `node_image_id` - The OCID of the image running on the nodes in the node pool.
5555
* `node_image_name` - The name of the image running on the nodes in the node pool.
56+
* `node_metadata` - A list of key/value pairs to add to each underlyingOracle Cloud Infrastructure instance in the node pool.
5657
* `node_shape` - The name of the node shape of the nodes in the node pool.
5758
* `nodes` - The nodes in the node pool.
5859
* `availability_domain` - The name of the availability domain in which this node is placed.

website/docs/r/containerengine_node_pool.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ resource "oci_containerengine_node_pool" "test_node_pool" {
3131
key = "${var.node_pool_initial_node_labels_key}"
3232
value = "${var.node_pool_initial_node_labels_value}"
3333
}
34+
node_metadata = "${var.node_pool_node_metadata}"
3435
quantity_per_subnet = "${var.node_pool_quantity_per_subnet}"
3536
ssh_public_key = "${var.node_pool_ssh_public_key}"
3637
}
@@ -49,6 +50,7 @@ The following arguments are supported:
4950
* `name` - (Required) (Updatable) The name of the node pool. Avoid entering confidential information.
5051
* `node_image_name` - (Optional) The name of the image running on the nodes in the node pool. Cannot be used when `node_image_id` is specified.
5152
* `node_image_id` - (Optional) The OCID of the image running on the nodes in the node pool. Cannot be used when `node_image_name` is specified.
53+
* `node_metadata` - (Optional) A list of key/value pairs to add to each underlyingOracle Cloud Infrastructure instance in the node pool.
5254
* `node_shape` - (Required) The name of the node shape of the nodes in the node pool.
5355
* `quantity_per_subnet` - (Optional) (Updatable) The number of nodes to create in each subnet.
5456
* `ssh_public_key` - (Optional) The SSH public key to add to each node in the node pool.
@@ -72,6 +74,7 @@ The following attributes are exported:
7274
* `name` - The name of the node pool.
7375
* `node_image_id` - The OCID of the image running on the nodes in the node pool.
7476
* `node_image_name` - The name of the image running on the nodes in the node pool.
77+
* `node_metadata` - A list of key/value pairs to add to each underlyingOracle Cloud Infrastructure instance in the node pool.
7578
* `node_shape` - The name of the node shape of the nodes in the node pool.
7679
* `nodes` - The nodes in the node pool.
7780
* `availability_domain` - The name of the availability domain in which this node is placed.

0 commit comments

Comments
 (0)