Skip to content

Commit 9d4bb28

Browse files
committed
add Freeform and Defined Tags support
Fix: #10 #11 #12 #13 #18 #20
1 parent bb6d829 commit 9d4bb28

File tree

7 files changed

+68
-0
lines changed

7 files changed

+68
-0
lines changed

CHANGELOG.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ Given a version number MAJOR.MINOR.PATCH:
1414
* MINOR version when adding functionality in a backwards compatible manner,
1515
* PATCH version when making backwards compatible bug fixes.
1616
17+
== 2.2.0 - unreleased
18+
19+
=== New features
20+
21+
* Add support for freeform and defined for instances, vnics and block volumes (Fix #10, #11, #12, #13, #18, #20)
22+
* Add "module watermark" freeform tags: module defined and user defined freeform tags are merged on the final resource.
23+
1724
== 2.1.0 - 2021-03-02
1825

1926
=== New features

examples/instances_fixed_shape/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ module "instance_nonflex" {
2222
source = "oracle-terraform-modules/compute-instance/oci"
2323
# general oci parameters
2424
compartment_ocid = var.compartment_ocid
25+
freeform_tags = var.freeform_tags
26+
defined_tags = var.defined_tags
2527
# compute instance parameters
2628
ad_number = var.instance_ad_number
2729
instance_count = var.instance_count
@@ -49,6 +51,8 @@ module "instance_nonflex_custom" {
4951
source = "oracle-terraform-modules/compute-instance/oci"
5052
# general oci parameters
5153
compartment_ocid = var.compartment_ocid
54+
freeform_tags = var.freeform_tags
55+
defined_tags = var.defined_tags
5256
# compute instance parameters
5357
ad_number = var.instance_ad_number
5458
instance_count = var.instance_count

examples/instances_fixed_shape/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ variable "compartment_ocid" {
4141
# no default value, asking user to explicitly set this variable's value. see codingconventions.adoc
4242
}
4343

44+
variable "freeform_tags" {
45+
description = "simple key-value pairs to tag the resources created using freeform tags."
46+
type = map(string)
47+
default = null
48+
}
49+
50+
variable "defined_tags" {
51+
description = "predefined and scoped to a namespace to tag the resources created using defined tags."
52+
type = map(string)
53+
default = null
54+
}
55+
4456
# compute instance parameters
4557

4658
variable "instance_ad_number" {

examples/instances_flex_shape/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ module "instance_flex" {
2323
source = "oracle-terraform-modules/compute-instance/oci"
2424
# general oci parameters
2525
compartment_ocid = var.compartment_ocid
26+
freeform_tags = var.freeform_tags
27+
defined_tags = var.defined_tags
2628
# compute instance parameters
2729
ad_number = var.instance_ad_number
2830
instance_count = var.instance_count
@@ -49,6 +51,8 @@ module "instance_flex_custom" {
4951
source = "oracle-terraform-modules/compute-instance/oci"
5052
# general oci parameters
5153
compartment_ocid = var.compartment_ocid
54+
freeform_tags = var.freeform_tags
55+
defined_tags = var.defined_tags
5256
# compute instance parameters
5357
ad_number = null
5458
instance_count = 4

examples/instances_flex_shape/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ variable "compartment_ocid" {
4141
# no default value, asking user to explicitly set this variable's value. see codingconventions.adoc
4242
}
4343

44+
variable "freeform_tags" {
45+
description = "simple key-value pairs to tag the resources created using freeform tags."
46+
type = map(string)
47+
default = null
48+
}
49+
50+
variable "defined_tags" {
51+
description = "predefined and scoped to a namespace to tag the resources created using defined tags."
52+
type = map(string)
53+
default = null
54+
}
55+
4456
# compute instance parameters
4557

4658
variable "instance_ad_number" {

main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ resource "oci_core_instance" "this" {
8484
skip_source_dest_check = var.skip_source_dest_check
8585
// Current implementation requires providing a list of subnets when using ad-specific subnets
8686
subnet_id = data.oci_core_subnet.this[count.index % length(data.oci_core_subnet.this.*.id)].id
87+
88+
freeform_tags = local.merged_freeform_tags
89+
defined_tags = var.defined_tags
8790
}
8891

8992
metadata = {
@@ -97,6 +100,9 @@ resource "oci_core_instance" "this" {
97100
source_type = var.source_type
98101
}
99102

103+
freeform_tags = local.merged_freeform_tags
104+
defined_tags = var.defined_tags
105+
100106
timeouts {
101107
create = var.instance_timeout
102108
}
@@ -122,6 +128,8 @@ resource "oci_core_volume" "this" {
122128
var.block_storage_sizes_in_gbs,
123129
floor(count.index / var.instance_count),
124130
)
131+
freeform_tags = local.merged_freeform_tags
132+
defined_tags = var.defined_tags
125133
}
126134

127135
####################

variables.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@ variable "instance_timeout" {
1313
default = "25m"
1414
}
1515

16+
variable "freeform_tags" {
17+
description = "simple key-value pairs to tag the resources created using freeform tags."
18+
type = map(string)
19+
default = null
20+
}
21+
22+
variable "defined_tags" {
23+
description = "predefined and scoped to a namespace to tag the resources created using defined tags."
24+
type = map(string)
25+
default = null
26+
}
27+
28+
locals {
29+
default_freeform_tags = {
30+
# * This list of freeform tags are added by default to user provided freeform tags (var.freeform_tags) if local.merged_freeform_tags is used
31+
terraformed = "Please do not edit manually"
32+
module = "oracle-terraform-modules/compute-instance/oci"
33+
}
34+
merged_freeform_tags = merge(local.default_freeform_tags, var.freeform_tags)
35+
}
36+
1637
# compute instance parameters
1738

1839
variable "ad_number" {

0 commit comments

Comments
 (0)