Skip to content

Commit

Permalink
Merge pull request Wilfred#3 from MichaHoffmann/add_heredoc_templates
Browse files Browse the repository at this point in the history
WIP add heredoc templates; only EOF marker at the moment
  • Loading branch information
MichaHoffmann authored Jun 23, 2021
2 parents d57a44c + 150c676 commit 7182e17
Show file tree
Hide file tree
Showing 903 changed files with 61,966 additions and 6,072 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
root = true

[*.{c,txt,js}]
[*.{cc,txt,js}]
indent_style = space
indent_size = 2
tab_width = 8
Expand Down
Empty file removed .gitattributes
Empty file.
17 changes: 17 additions & 0 deletions .github/workflows/acceptance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: acceptance
on:
push:

jobs:
unittests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: nixbuild/nix-quick-install-action@v5
- run: nix-shell --run 'tree-sitter test'
acceptance:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: nixbuild/nix-quick-install-action@v5
- run: nix-shell --run 'tree-sitter parse --quiet --stat example/real_world_stuff/*/*'
11 changes: 0 additions & 11 deletions .github/workflows/unittests.yaml

This file was deleted.

16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tree-sitter grammar for the [HCL](https://github.com/hashicorp/hcl/blob/main/hcl

Highlighting `example/example.hcl`:

![Highlighting Example](https://i.imgur.com/sgFcxLK.png)
![Highlighting Example](https://i.imgur.com/4XFVNVT.png)

## Developing

Expand All @@ -18,15 +18,16 @@ To run tests simply run `nix-shell --run 'tree-sitter test'`.

## Compliance

The directory `example/real_world_stuff` contains a corpus of hcl files that I found with the github query `language:HCL` for users `coreos` and `hashicorp`
The directory `example/real_world_stuff` contains a corpus of hcl files that I found with the github query `language:HCL` for users `coreos`, `hashicorp`, `oracle` and `terraform-community-modules`.

Given that some language features are still missing ( see TODO ) there are some expected parse errors:

```bash
nix-shell --run 'tree-sitter parse --quiet --stat example/real_world_stuff/*/*'
...
...
Total parses: 1130; successful parses: 1053; failed parses: 77; success percentage: 93.19%
tree-sitter parse --quiet --stat example/real_world_stuff/*/*

example/real_world_stuff/oracle/oracle%opengrok%opengrok-indexer%src%test%resources%analysis%terraform%sample.tf 1 ms (ERROR [205, 8] - [214, 1])

Total parses: 2015; successful parses: 2014; failed parses: 1; success percentage: 99.95%

```

Expand All @@ -40,4 +41,5 @@ The aim is to build unit testcases from selected failure classes and slowly get
* [x] add quoted templates
* [x] add quoted template interpolations
* [ ] add quoted template directives
* [ ] add heredoc templates
* [x] add heredoc templates

5 changes: 5 additions & 0 deletions example/example.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ resource_1 "strlit1" "strlit2" {
tpl1 = "prefix-${var.bar}"
tpl2 = "prefix-${func("bar")}"
tpl3 = "prefix-${func("nested-${var.bar}")}"
tpl4 = <<EOF
prefix
${func("foo${ var.bar }")}
suffix
EOF

nested_resource_1 {
attr1 = 2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Availability Domain
data "oci_identity_availability_domains" "ADs" {
compartment_id = "${var.oracle_tenancy_ocid}"
filter {
name = "name"
values = ["${var.director_ad}"]
}
}

data "oci_identity_compartments" "Compartments" {
compartment_id = "${var.oracle_tenancy_ocid}"
filter {
name = "name"
values = ["${var.director_compartment_name}"]
}
}

data "oci_core_virtual_networks" "VCNs" {
compartment_id = "${data.null_data_source.SetupConfig.inputs.compartment_id}"
filter {
name = "display_name"
values = ["${var.director_vcn}"]
}
}

data "null_data_source" "SetupConfig" {
inputs = {
ad_name = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[0],"name")}"
compartment_id = "${lookup(data.oci_identity_compartments.Compartments.compartments[0],"id")}"
}
}

data "null_data_source" "VCN" {
inputs = {
id = "${lookup(data.oci_core_virtual_networks.VCNs.virtual_networks[0], "id")}"
dhcp_options_id = "${lookup(data.oci_core_virtual_networks.VCNs.virtual_networks[0], "default_dhcp_options_id")}"
default_route_table_id = "${lookup(data.oci_core_virtual_networks.VCNs.virtual_networks[0], "default_route_table_id")}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
resource "oci_core_virtual_network" "VCN" {
cidr_block = "${var.vcn_cidr}"
compartment_id = "${data.null_data_source.SetupConfig.outputs["compartment_id"]}"
display_name = "${var.director_vcn}"
}
*/

resource "oci_core_security_list" "ci_public_all" {
compartment_id = "${data.null_data_source.SetupConfig.inputs.compartment_id}"
display_name = "ci_public_all"
vcn_id = "${data.null_data_source.VCN.inputs.id}"
egress_security_rules = [{
protocol = "all"
destination = "0.0.0.0/0"
}]
ingress_security_rules = [{
protocol = "all"
source = "0.0.0.0/0"
}]
}

resource "oci_core_subnet" "director_subnet" {
availability_domain = "${data.null_data_source.SetupConfig.inputs.ad_name}"
cidr_block = "${var.director_subnet_cidr}"
display_name = "ci_director_subnet_${replace(data.null_data_source.SetupConfig.inputs.ad_name, "-", "_")}"
dhcp_options_id = "${data.null_data_source.VCN.inputs.dhcp_options_id}"
compartment_id = "${data.null_data_source.SetupConfig.inputs.compartment_id}"
vcn_id = "${data.null_data_source.VCN.inputs.id}"
route_table_id = "${data.null_data_source.VCN.inputs.default_route_table_id}"
security_list_ids = ["${oci_core_security_list.ci_public_all.id}"]
prohibit_public_ip_on_vnic = false
}

resource "oci_core_subnet" "bats_subnet1" {
availability_domain = "${data.null_data_source.SetupConfig.inputs.ad_name}"
cidr_block = "${var.bats_subnet1_cidr}"
display_name = "ci_bats_subnet1_${replace(data.null_data_source.SetupConfig.inputs.ad_name, "-", "_")}"
dhcp_options_id = "${data.null_data_source.VCN.inputs.dhcp_options_id}"
compartment_id = "${data.null_data_source.SetupConfig.inputs.compartment_id}"
vcn_id = "${data.null_data_source.VCN.inputs.id}"
route_table_id = "${data.null_data_source.VCN.inputs.default_route_table_id}"
security_list_ids = ["${oci_core_security_list.ci_public_all.id}"]
prohibit_public_ip_on_vnic = false
}

resource "oci_core_subnet" "bats_subnet2" {
availability_domain = "${data.null_data_source.SetupConfig.inputs.ad_name}"
cidr_block = "${var.bats_subnet2_cidr}"
display_name = "ci_bats_subnet2_${replace(data.null_data_source.SetupConfig.inputs.ad_name, "-", "_")}"
dhcp_options_id = "${data.null_data_source.VCN.inputs.dhcp_options_id}"
compartment_id = "${data.null_data_source.SetupConfig.inputs.compartment_id}"
vcn_id = "${data.null_data_source.VCN.inputs.id}"
route_table_id = "${data.null_data_source.VCN.inputs.default_route_table_id}"
security_list_ids = ["${oci_core_security_list.ci_public_all.id}"]
prohibit_public_ip_on_vnic = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
output vcn {
value = "${var.director_vcn}"
}
output subnet_id {
value = "${oci_core_subnet.director_subnet.id}"

}
output compartment_id {
value = "${oci_core_subnet.director_subnet.compartment_id}"
}

output ad {
value = "${oci_core_subnet.director_subnet.availability_domain}"
}

output subnet_name {
value = "${oci_core_subnet.director_subnet.display_name}"
}
output subnet_cidr {
value = "${oci_core_subnet.director_subnet.cidr_block}"
}

output subnet_gw {
value = "${cidrhost(oci_core_subnet.director_subnet.cidr_block, 1)}"
}

output subnet_first_ip {
value = "${cidrhost(oci_core_subnet.director_subnet.cidr_block, 2)}"
}

output bats_subnet1_name {
value = "${oci_core_subnet.bats_subnet1.display_name}"
}

output bats_subnet1_cidr {
value = "${oci_core_subnet.bats_subnet1.cidr_block}"
}

output bats_subnet1_gw {
value ="${cidrhost(oci_core_subnet.bats_subnet1.cidr_block, 1)}"
}

output bats_subnet1_reserved {
value = "${cidrhost(oci_core_subnet.bats_subnet1.cidr_block, 2)} - ${cidrhost(oci_core_subnet.bats_subnet1.cidr_block, 9)}"
}

output bats_subnet1_static {
value = "${cidrhost(oci_core_subnet.bats_subnet1.cidr_block, 10)} - ${cidrhost(oci_core_subnet.bats_subnet1.cidr_block, 30)}"
}

output bats_subnet1_static_ip {
value = "${cidrhost(oci_core_subnet.bats_subnet1.cidr_block, 30)}"
}

output bats_subnet2_name {
value = "${oci_core_subnet.bats_subnet2.display_name}"
}

output bats_subnet2_cidr {
value = "${oci_core_subnet.bats_subnet2.cidr_block}"
}

output bats_subnet2_gw {
value ="${cidrhost(oci_core_subnet.bats_subnet2.cidr_block, 1)}"
}

output bats_subnet2_reserved {
value = "${cidrhost(oci_core_subnet.bats_subnet2.cidr_block, 2)} - ${cidrhost(oci_core_subnet.bats_subnet2.cidr_block, 9)}"
}

output bats_subnet2_static {
value = "${cidrhost(oci_core_subnet.bats_subnet2.cidr_block, 10)} - ${cidrhost(oci_core_subnet.bats_subnet2.cidr_block, 30)}"
}

output bats_subnet2_static_ip {
value = "${cidrhost(oci_core_subnet.bats_subnet2.cidr_block, 30)}"
}

/*
output director_subnet {
value = <<EOS
{
"subnet_id" : "${oci_core_subnet.director_subnet.id}",
"compartment_id" : "${oci_core_subnet.director_subnet.compartment_id}",
"ad" : "${oci_core_subnet.director_subnet.availability_domain}",
"vcn": "${var.director_vcn}",
"subnet_name" : "${oci_core_subnet.director_subnet.display_name}",
"subnet_cidr" : "${oci_core_subnet.director_subnet.cidr_block}",
"subnet_gw" : "${cidrhost(oci_core_subnet.director_subnet.cidr_block, 1)}",
"director_ip" : "${cidrhost(oci_core_subnet.director_subnet.cidr_block, 2)}"
}
EOS
}
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
provider "oci" {
tenancy_ocid = "${var.oracle_tenancy_ocid}"
user_ocid = "${var.oracle_user_ocid}"
fingerprint = "${var.oracle_fingerprint}"
private_key_path = "${var.oracle_private_key_path}"
region = "${var.oracle_region}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Authentication
variable "oracle_tenancy_ocid" {}
variable "oracle_user_ocid" {}
variable "oracle_fingerprint" {}
variable "oracle_private_key_path" {}

# Compartment to create resources in
variable "director_compartment_name" {}
variable "director_vcn" {}

# Cloud services
variable oracle_region {
default = "us-phoenix-1"
}

# Networking
variable "vcn_cidr" {
default = "10.0.0.0/16"
}

variable "director_subnet_cidr" {
}

variable "director_ad" {
default = "WZYX:PHX-AD-1"
}

variable "bats_subnet1_cidr" {
}

variable "bats_subnet2_cidr" {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
The Universal Permissive License (UPL), Version 1.0*/


# Get list of Availability Domains
data "oci_identity_availability_domains" "ADs" {
compartment_id = "${var.tenancy_ocid}"
}

# Get name of Availability Domains
data "template_file" "deployment_ad" {
count = "${length(var.AD)}"
template = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.AD[count.index] - 1], "name")}"
}

# Get list of Fault Domains
data "oci_identity_fault_domains" "fds" {
count = "${length(var.AD)}"
availability_domain = "${element(data.template_file.deployment_ad.*.rendered, count.index)}"
compartment_id = "${var.compartment_ocid}"
}

locals {
fds = "${flatten(concat(data.oci_identity_fault_domains.fds.*.fault_domains))}"
faultdomains_per_ad = 3
}

# Get name of Fault Domains
data "template_file" "deployment_fd" {
template = "$${name}"
count = "${length(var.AD) * (local.faultdomains_per_ad) }"
vars = {
name = "${lookup(local.fds[count.index], "name")}"
}
}

# Get latest Oracle Linux image
data "oci_core_images" "InstanceImageOCID" {
compartment_id = "${var.tenancy_ocid}"
operating_system = "${var.InstanceOS}"
operating_system_version = "${var.linux_os_version}"
filter {
name = "display_name"
values = ["^.*Oracle[^G]*$"]
regex = true
}
}

# Get swift object storage name for Service Gateway
data "oci_core_services" "svcgtw_services" {
filter {
name = "name"
values = [".*Object.*Storage"]
regex = true
}
}
Loading

0 comments on commit 7182e17

Please sign in to comment.