Skip to content

Commit 8de8934

Browse files
authored
updated vcn cidr look up method and removed deprecated vcn_cidr (#37)
Signed-off-by: Ali Mukadam <[email protected]>
1 parent aeced51 commit 8de8934

File tree

13 files changed

+34
-63
lines changed

13 files changed

+34
-63
lines changed

CHANGELOG.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ The format is based on {uri-changelog}[Keep a Changelog].
1919
* Set minimum Terraform version to 1.0.0
2020
* OCI home region provider now expected as parameter to providers
2121
* Renamed notification variables (#18)
22-
** create_bastion -> create_bastion_host
2322
** enable_notification -> enable_bastion_notification
2423
** notification_endpoint -> bastion_notification_endpoint
2524
** notification_protocol -> bastion_notification_protocol
2625
** notification_topic -> bastion_notification_topic
2726
** Renamed variable bastion_upgrade --> upgrade_bastion
2827
** Renamed variable timezone --> bastion_timezone
29-
** Renamed variable tags --> bastion_tags
28+
** Renamed variable tags --> freeform_tags
3029
* Changed bastion access from a single CIDR to a list of CIDR blocks (#29)
3130
* AD lookup mechanism reimplemented to remove dependency on deprecated template_file data source (#27)
3231
* Replaced all deprecated template_file data source with templatefile function (#27)
3332

3433
== Deletion
3534
* Removed provider identity parameters except for tenancy_id
35+
* Removed create_bastion_host parameter (#36)
3636

3737
= v2.0.0 (December 8, 2020)
3838
* Added support for flex shapes (#11)

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
# Terraform OCI Bastion for Oracle Cloud Infrastructure
22

3-
[changelog]: https://github.com/oracle-terraform-modules/terraform-oci-bastion/blob/master/CHANGELOG.adoc
4-
[contributing]: https://github.com/oracle-terraform-modules/terraform-oci-bastion/blob/master/CONTRIBUTING.adoc
5-
[contributors]: https://github.com/oracle-terraform-modules/terraform-oci-bastion/blob/master/CONTRIBUTORS.adoc
6-
[docs]: https://github.com/oracle-terraform-modules/terraform-oci-bastion/tree/master/docs
3+
[changelog]: https://github.com/oracle-terraform-modules/terraform-oci-bastion/blob/main/CHANGELOG.adoc
4+
[contributing]: https://github.com/oracle-terraform-modules/terraform-oci-bastion/blob/main/CONTRIBUTING.adoc
5+
[contributors]: https://github.com/oracle-terraform-modules/terraform-oci-bastion/blob/main/CONTRIBUTORS.adoc
6+
[docs]: https://github.com/oracle-terraform-modules/terraform-oci-bastion/tree/main/docs
77

8-
[license]: https://github.com/oracle-terraform-modules/terraform-oci-bastion/blob/master/LICENSE
8+
[license]: https://github.com/oracle-terraform-modules/terraform-oci-bastion/blob/main/LICENSE
99
[canonical_license]: https://oss.oracle.com/licenses/upl/
1010

1111
[oci]: https://cloud.oracle.com/cloud-infrastructure
1212
[oci_documentation]: https://docs.cloud.oracle.com/iaas/Content/home.htm
1313

1414
[oracle]: https://www.oracle.com
15-
[prerequisites]: https://github.com/oracle-terraform-modules/terraform-oci-bastion/blob/master/docs/prerequisites.adoc
15+
[prerequisites]: https://github.com/oracle-terraform-modules/terraform-oci-bastion/blob/main/docs/prerequisites.adoc
1616

17-
[quickstart]: https://github.com/oracle-terraform-modules/terraform-oci-bastion/blob/master/docs/quickstart.adoc
17+
[quickstart]: https://github.com/oracle-terraform-modules/terraform-oci-bastion/blob/main/docs/quickstart.adoc
1818
[repo]: https://github.com/oracle/terraform-oci-bastion
1919
[reuse]: https://github.com/oracle/terraform-oci-bastion/examples/db
2020
[subnets]: https://erikberg.com/notes/networks.html
2121
[terraform]: https://www.terraform.io
2222
[terraform_cidr_subnet]: http://blog.itsjustcode.net/blog/2017/11/18/terraform-cidrsubnet-deconstructed/
2323
[terraform_hashircorp_examples]: https://github.com/hashicorp/terraform-guides/tree/master/infrastructure-as-code/terraform-0.12-examples
2424
[terraform_oci]: https://www.terraform.io/docs/providers/oci/index.html
25-
[terraform_options]: https://github.com/oracle-terraform-modules/terraform-oci-bastion/blob/master/docs/terraformoptions.adoc
25+
[terraform_options]: https://github.com/oracle-terraform-modules/terraform-oci-bastion/blob/main/docs/terraformoptions.adoc
2626
[terraform_oci_examples]: https://github.com/terraform-providers/terraform-provider-oci/tree/master/examples
2727
[terraform_oci_oke]: https://github.com/oracle-terraform-modules/terraform-oci-oke
2828

compute.tf

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
resource "oci_core_instance" "bastion" {
55
availability_domain = data.oci_identity_availability_domain.ad.name
66
compartment_id = var.compartment_id
7-
freeform_tags = var.bastion_tags
7+
freeform_tags = var.freeform_tags
88

99
agent_config {
1010

@@ -22,7 +22,7 @@ resource "oci_core_instance" "bastion" {
2222
assign_public_ip = var.bastion_type == "public" ? true : false
2323
display_name = var.label_prefix == "none" ? "bastion-vnic" : "${var.label_prefix}-bastion-vnic"
2424
hostname_label = "bastion"
25-
subnet_id = oci_core_subnet.bastion[0].id
25+
subnet_id = oci_core_subnet.bastion.id
2626
}
2727

2828
display_name = var.label_prefix == "none" ? "bastion" : "${var.label_prefix}-bastion"
@@ -39,7 +39,7 @@ resource "oci_core_instance" "bastion" {
3939

4040
metadata = {
4141
ssh_authorized_keys = var.ssh_public_key != "" ? var.ssh_public_key : file(var.ssh_public_key_path)
42-
user_data = data.cloudinit_config.bastion[0].rendered
42+
user_data = data.cloudinit_config.bastion.rendered
4343
}
4444

4545
shape = lookup(var.bastion_shape, "shape", "VM.Standard.E2.2")
@@ -64,5 +64,4 @@ resource "oci_core_instance" "bastion" {
6464
create = "60m"
6565
}
6666

67-
count = var.create_bastion_host == true ? 1 : 0
6867
}

datasources.tf

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
data "oci_identity_availability_domain" "ad" {
55
compartment_id = var.tenancy_id
6-
ad_number = var.availability_domain
6+
ad_number = var.availability_domain
77
}
88

99
data "oci_core_vcn" "vcn" {
@@ -35,36 +35,29 @@ data "cloudinit_config" "bastion" {
3535
}
3636
)
3737
}
38-
count = var.create_bastion_host == true ? 1 : 0
3938
}
4039

4140
# Gets a list of VNIC attachments on the bastion instance
4241
data "oci_core_vnic_attachments" "bastion_vnics_attachments" {
4342
availability_domain = data.oci_identity_availability_domain.ad.name
4443
compartment_id = var.compartment_id
4544
depends_on = [oci_core_instance.bastion]
46-
instance_id = oci_core_instance.bastion[0].id
47-
48-
count = var.create_bastion_host == true ? 1 : 0
45+
instance_id = oci_core_instance.bastion.id
4946
}
5047

5148
# Gets the OCID of the first (default) VNIC on the bastion instance
5249
data "oci_core_vnic" "bastion_vnic" {
5350
depends_on = [oci_core_instance.bastion]
54-
vnic_id = lookup(data.oci_core_vnic_attachments.bastion_vnics_attachments[0].vnic_attachments[0], "vnic_id")
55-
56-
count = var.create_bastion_host == true ? 1 : 0
51+
vnic_id = lookup(data.oci_core_vnic_attachments.bastion_vnics_attachments.vnic_attachments[0], "vnic_id")
5752
}
5853

5954
data "oci_core_instance" "bastion" {
6055
depends_on = [oci_core_instance.bastion]
61-
instance_id = oci_core_instance.bastion[0].id
62-
63-
count = var.create_bastion_host == true ? 1 : 0
56+
instance_id = oci_core_instance.bastion.id
6457
}
6558

6659
data "oci_ons_notification_topic" "bastion_notification" {
6760
topic_id = oci_ons_notification_topic.bastion_notification[0].topic_id
6861

69-
count = (var.create_bastion_host == true && var.enable_bastion_notification == true) ? 1 : 0
62+
count = var.enable_bastion_notification == true ? 1 : 0
7063
}

docs/terraformoptions.adoc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,6 @@ Ensure you review the {uri-terraform-dependencies}[dependencies].
108108
|Values
109109
|Default
110110

111-
|`create_bastion_host`
112-
|whether to create the bastion host
113-
| true/false
114-
|true
115-
116111
|`bastion_image_id`
117112
|Provide a custom image id for the bastion host or leave as Autonomous.
118113
|imageid/Autonomous
@@ -210,13 +205,13 @@ Ensure you review the {uri-terraform-dependencies}[dependencies].
210205
|Values
211206
|Default
212207

213-
|`bastion_tags`
208+
|`freeform_tags`
214209
|Freeform tags for bastion.
215210
|
216211
|
217212
[source]
218213
----
219-
bastion_tags = {
214+
freeform_tags = {
220215
access = "public"
221216
environment = "dev"
222217
role = "bastion"

examples/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,11 @@ module "bastion" {
8989
9090
vcn_id = var.vcn_id
9191
92-
create_bastion_host = true
93-
9492
ssh_public_key_path = "~/.ssh/id_rsa.pub"
9593
9694
upgrade_bastion = false
9795
98-
bastion_tags = {
96+
freeform_tags = {
9997
access = "public"
10098
environment = "dev"
10199
role = "bastion"

examples/main.tf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ module "bastion" {
2929

3030
vcn_id = var.vcn_id
3131

32-
create_bastion_host = true
33-
3432
ssh_public_key_path = "~/.ssh/id_rsa.pub"
3533

3634
upgrade_bastion = false
3735

38-
bastion_tags = {
36+
freeform_tags = {
3937
access = "public"
4038
environment = "dev"
4139
role = "bastion"

locals.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ locals {
2626

2727
tcp_protocol = 6
2828

29-
vcn_cidr = data.oci_core_vcn.vcn.cidr_block
29+
# we expect the bastion to be in the first cidr block in the list of cidr blocks
30+
vcn_cidr = element(data.oci_core_vcn.vcn.cidr_blocks, 0)
3031
}

ons.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ resource "oci_ons_notification_topic" "bastion_notification" {
55
compartment_id = var.compartment_id
66
name = var.label_prefix == "none" ? var.bastion_notification_topic : "${var.label_prefix}-${var.bastion_notification_topic}"
77

8-
count = (var.create_bastion_host == true && var.enable_bastion_notification == true) ? 1 : 0
8+
count = var.enable_bastion_notification == true ? 1 : 0
99
}
1010

1111
resource "oci_ons_subscription" "bastion_notification" {
@@ -14,7 +14,7 @@ resource "oci_ons_subscription" "bastion_notification" {
1414
protocol = var.bastion_notification_protocol
1515
topic_id = oci_ons_notification_topic.bastion_notification[0].topic_id
1616

17-
count = (var.create_bastion_host == true && var.enable_bastion_notification == true) ? 1 : 0
17+
count = var.enable_bastion_notification == true ? 1 : 0
1818
}
1919

2020
resource "oci_identity_dynamic_group" "bastion_notification" {
@@ -26,7 +26,7 @@ resource "oci_identity_dynamic_group" "bastion_notification" {
2626
matching_rule = "ALL {instance.id = '${join(",", data.oci_core_instance.bastion.*.id)}'}"
2727
name = var.label_prefix == "none" ? "bastion-notification" : "${var.label_prefix}-bastion-notification"
2828

29-
count = (var.create_bastion_host == true && var.enable_bastion_notification == true) ? 1 : 0
29+
count = var.enable_bastion_notification == true ? 1 : 0
3030
}
3131

3232
resource "oci_identity_policy" "bastion_notification" {
@@ -38,5 +38,5 @@ resource "oci_identity_policy" "bastion_notification" {
3838
name = var.label_prefix == "none" ? "bastion-notification" : "${var.label_prefix}-bastion-notification"
3939
statements = ["Allow dynamic-group ${oci_identity_dynamic_group.bastion_notification[0].name} to use ons-topic in compartment id ${var.compartment_id} where request.permission='ONS_TOPIC_PUBLISH'"]
4040

41-
count = (var.create_bastion_host == true && var.enable_bastion_notification == true) ? 1 : 0
41+
count = var.enable_bastion_notification == true ? 1 : 0
4242
}

security.tf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
resource "oci_core_security_list" "bastion" {
55
compartment_id = var.compartment_id
66
display_name = var.label_prefix == "none" ? "bastion" : "${var.label_prefix}-bastion"
7-
freeform_tags = var.bastion_tags
7+
freeform_tags = var.freeform_tags
88

99
egress_security_rules {
1010
protocol = local.all_protocols
@@ -27,6 +27,4 @@ resource "oci_core_security_list" "bastion" {
2727
}
2828
}
2929
vcn_id = var.vcn_id
30-
31-
count = var.create_bastion_host == true ? 1 : 0
3230
}

0 commit comments

Comments
 (0)