Skip to content

Commit a8a4801

Browse files
authored
feat: Add assign_dns var to support disabled DNS (#77)
* feat: Add assign_dns var to support disabled DNS Signed-off-by: Devon Crouse <[email protected]> * fix: Add unique suffix to instance principal policy name Signed-off-by: Devon Crouse <[email protected]> Signed-off-by: Devon Crouse <[email protected]>
1 parent 0ca0b72 commit a8a4801

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

compute.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017, 2021 Oracle Corporation and/or affiliates. All rights reserved.
1+
# Copyright 2017, 2022 Oracle Corporation and/or affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
33

44
resource "oci_core_instance" "operator" {
@@ -26,7 +26,7 @@ resource "oci_core_instance" "operator" {
2626
create_vnic_details {
2727
assign_public_ip = false
2828
display_name = var.label_prefix == "none" ? "operator-vnic" : "${var.label_prefix}-operator-vnic"
29-
hostname_label = var.label_prefix == "none" ? "operator" : "${var.label_prefix}-operator"
29+
hostname_label = var.assign_dns ? var.label_prefix == "none" ? "operator" : "${var.label_prefix}-operator" : null
3030
nsg_ids = concat(var.nsg_ids, [oci_core_network_security_group.operator.id])
3131
subnet_id = oci_core_subnet.operator.id
3232
}

instance_principal.tf

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2022, Oracle Corporation and/or affiliates. All rights reserved.
1+
# Copyright (c) 2022 Oracle Corporation and/or affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
33

44
resource "random_id" "dynamic_group_suffix" {
@@ -18,7 +18,7 @@ resource "oci_identity_dynamic_group" "operator_group" {
1818
description = "dynamic group %{ if var.label_prefix != "none" }with label ${var.label_prefix}%{ endif } to allow operator to invoke services"
1919

2020
lifecycle {
21-
ignore_changes = [defined_tags]
21+
ignore_changes = [defined_tags, name]
2222
}
2323

2424
matching_rule = "ALL {instance.id = '${join(",", data.oci_core_instance.operator.*.id)}'}"
@@ -36,9 +36,17 @@ resource "oci_identity_policy" "operator_group_policy" {
3636

3737
compartment_id = var.compartment_id
3838
description = "policy to allow operator host to call services"
39-
name = join("-", compact([ local.dynamic_group_prefix, "operator-instance-principal" ]))
39+
name = join("-", compact([
40+
random_id.dynamic_group_suffix.keepers.label_prefix,
41+
"operator-instance-principal",
42+
random_id.dynamic_group_suffix.hex
43+
]))
4044
statements = ["Allow dynamic-group ${oci_identity_dynamic_group.operator_group[0].name} to manage all-resources in compartment id ${var.compartment_id}"]
4145

46+
lifecycle {
47+
ignore_changes = [name]
48+
}
49+
4250
count = var.enable_operator_instance_principal == true ? 1 : 0
4351
}
4452

subnets.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# Copyright 2017, 2021 Oracle Corporation and/or affiliates. All rights reserved.
1+
# Copyright 2017, 2022 Oracle Corporation and/or affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
33

44
resource "oci_core_subnet" "operator" {
55
cidr_block = local.operator_subnet
66
compartment_id = var.compartment_id
77
display_name = var.label_prefix == "none" ? "operator" : "${var.label_prefix}-operator"
8-
dns_label = "operator"
8+
dns_label = var.assign_dns ? "operator" : null
99
freeform_tags = var.freeform_tags
1010
prohibit_public_ip_on_vnic = true
1111
route_table_id = var.nat_route_id
1212
security_list_ids = [oci_core_security_list.operator.id]
1313
vcn_id = var.vcn_id
1414

1515
lifecycle {
16-
ignore_changes = [freeform_tags]
16+
ignore_changes = [dns_label, freeform_tags]
1717
}
1818
}

variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, 2021 Oracle Corporation and/or affiliates. All rights reserved.
1+
# Copyright (c) 2019, 2022 Oracle Corporation and/or affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
33

44
# provider parameters
@@ -24,6 +24,12 @@ variable "label_prefix" {
2424

2525
# network parameters
2626

27+
variable "assign_dns" {
28+
default = true
29+
description = "Whether to assign DNS records for operator subnet"
30+
type = bool
31+
}
32+
2733
variable "availability_domain" {
2834
description = "the AD to place the operator host"
2935
default = 1

0 commit comments

Comments
 (0)