Skip to content

Commit 02db190

Browse files
committed
feat: Added code generation for new provider functions.
1 parent 81dfde8 commit 02db190

24 files changed

+738
-83
lines changed

.golangci.yml

+5
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,11 @@ issues:
854854
- gochecknoinits
855855
source: lint:allow_init
856856

857+
- text: (cuddle)
858+
linters:
859+
- wsl
860+
source: lint:allow_cuddle
861+
857862
# Independently from option `exclude` we use default exclude patterns, it can be disabled by this
858863
# option. To list all excluded by default patterns execute `golangci-lint run --help`. Default
859864
# value for this option is true.

bats/env_ensure.bats.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bats
2+
# https://bats-core.readthedocs.io/en/stable/writing-tests.html
3+
4+
@test "corefunc_env_ensure: attrs" {
5+
run bash -c "tfschema data show -format=json corefunc_env_ensure | jq -Mrc '.attributes[]'"
6+
7+
[ "$status" -eq 0 ]
8+
[[ ${lines[0]} == '{"name":"id","type":"number","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
9+
[[ ${lines[1]} == '{"name":"name","type":"string","required":true,"optional":false,"computed":false,"sensitive":false}' ]]
10+
[[ ${lines[2]} == '{"name":"pattern","type":"string","required":false,"optional":true,"computed":false,"sensitive":false}' ]]
11+
[[ ${lines[3]} == '{"name":"value","type":"string","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
12+
}

bats/str_camel.bats.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bats
2+
# https://bats-core.readthedocs.io/en/stable/writing-tests.html
3+
4+
@test "corefunc_str_camel: attrs" {
5+
run bash -c "tfschema data show -format=json corefunc_str_camel | jq -Mrc '.attributes[]'"
6+
7+
[ "$status" -eq 0 ]
8+
[[ ${lines[0]} == '{"name":"id","type":"number","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
9+
[[ ${lines[1]} == '{"name":"string","type":"string","required":true,"optional":false,"computed":false,"sensitive":false}' ]]
10+
[[ ${lines[2]} == '{"name":"value","type":"string","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
11+
}

bats/str_constant.bats.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bats
2+
# https://bats-core.readthedocs.io/en/stable/writing-tests.html
3+
4+
@test "corefunc_str_constant: attrs" {
5+
run bash -c "tfschema data show -format=json corefunc_str_constant | jq -Mrc '.attributes[]'"
6+
7+
[ "$status" -eq 0 ]
8+
[[ ${lines[0]} == '{"name":"id","type":"number","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
9+
[[ ${lines[1]} == '{"name":"string","type":"string","required":true,"optional":false,"computed":false,"sensitive":false}' ]]
10+
[[ ${lines[2]} == '{"name":"value","type":"string","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
11+
}

bats/str_kebab.bats.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bats
2+
# https://bats-core.readthedocs.io/en/stable/writing-tests.html
3+
4+
@test "corefunc_str_kebab: attrs" {
5+
run bash -c "tfschema data show -format=json corefunc_str_kebab | jq -Mrc '.attributes[]'"
6+
7+
[ "$status" -eq 0 ]
8+
[[ ${lines[0]} == '{"name":"id","type":"number","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
9+
[[ ${lines[1]} == '{"name":"string","type":"string","required":true,"optional":false,"computed":false,"sensitive":false}' ]]
10+
[[ ${lines[2]} == '{"name":"value","type":"string","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
11+
}

bats/str_pascal.bats.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bats
2+
# https://bats-core.readthedocs.io/en/stable/writing-tests.html
3+
4+
@test "corefunc_str_pascal: attrs" {
5+
run bash -c "tfschema data show -format=json corefunc_str_pascal | jq -Mrc '.attributes[]'"
6+
7+
[ "$status" -eq 0 ]
8+
[[ ${lines[0]} == '{"name":"acronym_caps","type":"bool","required":false,"optional":true,"computed":false,"sensitive":false}' ]]
9+
[[ ${lines[1]} == '{"name":"id","type":"number","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
10+
[[ ${lines[2]} == '{"name":"string","type":"string","required":true,"optional":false,"computed":false,"sensitive":false}' ]]
11+
[[ ${lines[3]} == '{"name":"value","type":"string","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
12+
}

bats/str_snake.bats.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bats
2+
# https://bats-core.readthedocs.io/en/stable/writing-tests.html
3+
4+
@test "corefunc_str_snake: attrs" {
5+
run bash -c "tfschema data show -format=json corefunc_str_snake | jq -Mrc '.attributes[]'"
6+
7+
[ "$status" -eq 0 ]
8+
[[ ${lines[0]} == '{"name":"id","type":"number","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
9+
[[ ${lines[1]} == '{"name":"string","type":"string","required":true,"optional":false,"computed":false,"sensitive":false}' ]]
10+
[[ ${lines[2]} == '{"name":"value","type":"string","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
11+
}

bats/str_truncate_label.bats.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bats
2+
# https://bats-core.readthedocs.io/en/stable/writing-tests.html
3+
4+
@test "corefunc_str_truncate_label: attrs" {
5+
run bash -c "tfschema data show -format=json corefunc_str_truncate_label | jq -Mrc '.attributes[]'"
6+
7+
[ "$status" -eq 0 ]
8+
[[ ${lines[0]} == '{"name":"id","type":"number","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
9+
[[ ${lines[1]} == '{"name":"label","type":"string","required":true,"optional":false,"computed":false,"sensitive":false}' ]]
10+
[[ ${lines[2]} == '{"name":"max_length","type":"number","required":false,"optional":true,"computed":false,"sensitive":false}' ]]
11+
[[ ${lines[3]} == '{"name":"prefix","type":"string","required":true,"optional":false,"computed":false,"sensitive":false}' ]]
12+
[[ ${lines[4]} == '{"name":"value","type":"string","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
13+
}

bats/tfschema.bats.sh

-83
This file was deleted.

bats/tfschema_listing.bats.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bats
2+
# https://bats-core.readthedocs.io/en/stable/writing-tests.html
3+
4+
@test "listing the data sources" {
5+
run tfschema data list corefunc
6+
7+
[ "$status" -eq 0 ]
8+
[[ ${lines[0]} == "corefunc_env_ensure" ]]
9+
[[ ${lines[1]} == "corefunc_str_camel" ]]
10+
[[ ${lines[2]} == "corefunc_str_constant" ]]
11+
[[ ${lines[3]} == "corefunc_str_kebab" ]]
12+
[[ ${lines[4]} == "corefunc_str_pascal" ]]
13+
[[ ${lines[5]} == "corefunc_str_snake" ]]
14+
[[ ${lines[6]} == "corefunc_str_truncate_label" ]]
15+
16+
}

generator/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Stub Generator
2+
3+
## Generator
4+
5+
This will accept a name, then generate the correct files needed to implement the provider functionality.
6+
7+
The name should match what the Terraform data source will be called (e.g., `corefunc_example`).
8+
9+
From this `generator/` directory, run the command.
10+
11+
```bash
12+
go run main.go --name corefunc_example
13+
```
14+
15+
After that, search the project for `@TODO` and make the appropriate changes. Exclude `./generator,*.md,.*.yml`.
16+
17+
## Checklist
18+
19+
* [ ] Generate the stub files.
20+
* [ ] In the new `*_data_source.go` file, update the `*SourceModel` struct.
21+
* [ ] In the new `*_data_source.go` file, update the Schema Attributes to match the `*SourceModel` struct.
22+
* [ ] In the new `*_data_source.go` file, implement the remainder of the `Read` function.
23+
* [ ] In the new test fixture file, implement the test cases.
24+
* [ ] In the new `*_data_source_fixture.tftpl` file, ensure the fixture is implemented correctly.
25+
* [ ] In the new `*_data_source_test.go` file, ensure the test references the fixture correctly.
26+
* [ ] Run the integration tests.
27+
* [ ] In the new `examples/data-sources/*/data-source.tf` file, ensure the example is implemented correctly.
28+
* [ ] In the new `examples/data-sources/*/terraform-plan.example` file, copy content or delete.
29+
* [ ] In the new `templates/data-sources/*.tmpl` file, update the template that will be used by the `tfplugindocs` package.
30+
* [ ] Generate the Terraform provider documentation.
31+
* [ ] Run `tfschema data show -format=json DATASOURCE | jq -Mrc '.attributes[]'`.
32+
* [ ] In the new `bats/*.bats.sh` file, update its contents to match the `tfschema` output.
33+
* [ ] Run the bats tests.

generator/bats/test.tmpl

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bats
2+
# https://bats-core.readthedocs.io/en/stable/writing-tests.html
3+
4+
@test "{{ .Snake }}: attrs" {
5+
run bash -c "tfschema data show -format=json {{ .Snake }} | jq -Mrc '.attributes[]'"
6+
7+
[ "$status" -eq 0 ]
8+
[[ ${lines[0]} == '@TODO' ]]
9+
}

0 commit comments

Comments
 (0)