Skip to content

Commit a5b20a7

Browse files
ahornacevladak
authored andcommitted
Add support for additional terraform definitions
1 parent b869b08 commit a5b20a7

File tree

8 files changed

+81
-6
lines changed

8 files changed

+81
-6
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/Ctags.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,32 @@ private void addTerraformSupport(List<String> command) {
453453
* equivalent of {Identifier} from HCL.lexh, so we must approximate with
454454
* the possibility of leaving out some matches.
455455
*/
456-
command.add("--kinddef-terraform=s,struct,Resource\\ names");
456+
command.add("--kinddef-terraform=r,resource,Resource\\ names");
457+
command.add("--kinddef-terraform=d,dataSource,Data\\ sources");
458+
command.add("--kinddef-terraform=m,module,Modules");
459+
command.add("--kinddef-terraform=o,outputValue,Output\\ values");
460+
command.add("--kinddef-terraform=p,provider,Providers");
461+
command.add("--kinddef-terraform=v,variable,Variables");
457462
command.add("--regex-terraform=" +
458463
"/^[[:space:]]*resource[[:space:]]*\\\"([[:alpha:]][-_[:alpha:]]*)\\\"[[:space:]]*" +
459464
"\\\"([[:alpha:]][-_[:alpha:]]*)\\\"[[:space:]]*\\{/" +
460-
"\\1.\\2/s/");
465+
"\\1.\\2/r/");
466+
command.add("--regex-terraform=" +
467+
"/^[[:space:]]*data[[:space:]]*\\\"([[:alpha:]][-_[:alpha:]]*)\\\"[[:space:]]*" +
468+
"\\\"([[:alpha:]][-_[:alpha:]]*)\\\"[[:space:]]*\\{/" +
469+
"\\1.\\2/d/");
470+
command.add("--regex-terraform=" +
471+
"/^[[:space:]]*module[[:space:]]*\\\"([[:alpha:]][-_[:alpha:]]*)\\\"[[:space:]]*\\{/" +
472+
"\\1/m/");
473+
command.add("--regex-terraform=" +
474+
"/^[[:space:]]*output[[:space:]]*\\\"([[:alpha:]][-_[:alpha:]]*)\\\"[[:space:]]*\\{/" +
475+
"\\1/o/");
476+
command.add("--regex-terraform=" +
477+
"/^[[:space:]]*provider[[:space:]]*\\\"([[:alpha:]][-_[:alpha:]]*)\\\"[[:space:]]*\\{/" +
478+
"\\1/p/");
479+
command.add("--regex-terraform=" +
480+
"/^[[:space:]]*variable[[:space:]]*\\\"([[:alpha:]][-_[:alpha:]]*)\\\"[[:space:]]*\\{/" +
481+
"\\1/v/");
461482
}
462483

463484
/**

opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/CtagsTest.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@
2424
package org.opengrok.indexer.analysis;
2525

2626
import java.io.File;
27+
import java.util.List;
2728

2829
import org.junit.jupiter.api.AfterAll;
2930
import org.junit.jupiter.api.BeforeAll;
3031
import org.junit.jupiter.api.Test;
32+
import org.junit.jupiter.params.ParameterizedTest;
33+
import org.junit.jupiter.params.provider.MethodSource;
3134
import org.opengrok.indexer.util.TestRepository;
3235

3336
import static org.junit.jupiter.api.Assertions.assertAll;
@@ -138,12 +141,38 @@ void bug19195() throws Exception {
138141
assertEquals(names.length, count, "function count");
139142
}
140143

141-
@Test
142-
void testTfTags() throws Exception {
143-
var defs = getDefs("terraform/test.tf");
144+
@ParameterizedTest
145+
@MethodSource("terraformTestParams")
146+
void testTfTags(final SingleTagTestData data) throws Exception {
147+
var defs = getDefs("terraform/" + data.file + ".tf");
144148
assertAll(
145149
() -> assertEquals(1, defs.getTags().size()),
146-
() -> assertEquals("oci_core_vcn.test_vcn", defs.getTags().get(0).symbol)
150+
() -> assertEquals(data.symbol, defs.getTags().get(0).symbol),
151+
() -> assertEquals(data.type, defs.getTags().get(0).type)
147152
);
148153
}
154+
155+
private static List<SingleTagTestData> terraformTestParams() {
156+
return List.of(
157+
new SingleTagTestData("data_source", "aws_ami.example", "dataSource"),
158+
new SingleTagTestData("module", "servers", "module"),
159+
new SingleTagTestData("output_value", "instance_ip_addr", "outputValue"),
160+
new SingleTagTestData("provider", "oci", "provider"),
161+
new SingleTagTestData("resource", "oci_core_vcn.test_vcn", "resource"),
162+
new SingleTagTestData("variable", "availability_zone_names", "variable")
163+
);
164+
}
165+
166+
private static class SingleTagTestData {
167+
private final String file;
168+
private final String symbol;
169+
private final String type;
170+
171+
SingleTagTestData(final String file, final String symbol, final String type) {
172+
this.file = file;
173+
this.symbol = symbol;
174+
this.type = type;
175+
}
176+
}
177+
149178
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
data "aws_ami" "example" {
2+
most_recent = true
3+
4+
owners = ["self"]
5+
tags = {
6+
Name = "app-server"
7+
Tested = "true"
8+
}
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module "servers" {
2+
source = "./app-cluster"
3+
4+
servers = 5
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "instance_ip_addr" {
2+
value = aws_instance.server.private_ip
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
provider "oci" {
2+
auth = "InstancePrincipal"
3+
region = "${var.region}"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
variable "availability_zone_names" {
2+
type = list(string)
3+
default = ["us-west-1a"]
4+
}

0 commit comments

Comments
 (0)