-
Notifications
You must be signed in to change notification settings - Fork 22
feat: allow validation
to be used with option
s
#202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ed30ba3
Add development instructions
dannykopping 7f41e4f
Relax option/validation conflicts, add tests
dannykopping 95bb13e
Add note about vendoring
dannykopping ec4fd40
Fix indentation
dannykopping e77ed5e
Add example usage
dannykopping File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,39 @@ | ||
# terraform-provider-coder | ||
|
||
See [Coder](https://github.com/coder/coder). | ||
Terraform provider for [Coder](https://github.com/coder/coder). | ||
|
||
### Developing | ||
|
||
Follow the instructions outlined in the [Terraform documentation](https://developer.hashicorp.com/terraform/cli/config/config-file#development-overrides-for-provider-developers) | ||
to setup your local Terraform to use your local version rather than the registry version. | ||
|
||
1. Create a file named `.terraformrc` in your `$HOME` directory | ||
2. Add the following content: | ||
```hcl | ||
provider_installation { | ||
# Override the coder/coder provider to use your local version | ||
dev_overrides { | ||
"coder/coder" = "/path/to/terraform-provider-coder" | ||
} | ||
|
||
# For all other providers, install them directly from their origin provider | ||
# registries as normal. If you omit this, Terraform will _only_ use | ||
# the dev_overrides block, and so no other providers will be available. | ||
direct {} | ||
} | ||
``` | ||
3. (optional, but recommended) Validate your configuration: | ||
1. Create a new `main.tf` file and include: | ||
```hcl | ||
terraform { | ||
required_providers { | ||
coder = { | ||
source = "coder/coder" | ||
} | ||
} | ||
} | ||
``` | ||
2. Run `terraform init` and observe a warning like `Warning: Provider development overrides are in effect` | ||
4. Run `go build -o terraform-provider-coder` to build the provider binary, which Terraform will try locate and execute | ||
5. All local Terraform runs will now use your local provider! | ||
6. _**NOTE**: we vendor in this provider into `github.com/coder/coder`, so if you're testing with a local clone then you should also run `go mod edit -replace github.com/coder/terraform-provider-coder=/path/to/terraform-provider-coder` in your clone._ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ func TestParameter(t *testing.T) { | |
} | ||
}, | ||
}, { | ||
Name: "ValidationWithOptions", | ||
Name: "RegexValidationWithOptions", | ||
Config: ` | ||
data "coder_parameter" "region" { | ||
name = "Region" | ||
|
@@ -88,7 +88,23 @@ func TestParameter(t *testing.T) { | |
} | ||
} | ||
`, | ||
ExpectError: regexp.MustCompile("conflicts with option"), | ||
ExpectError: regexp.MustCompile("a regex cannot be specified for a number type"), | ||
}, { | ||
Name: "MonotonicValidationWithNonNumberType", | ||
Config: ` | ||
data "coder_parameter" "region" { | ||
name = "Region" | ||
type = "string" | ||
option { | ||
name = "1" | ||
value = "1" | ||
} | ||
validation { | ||
monotonic = "increasing" | ||
} | ||
} | ||
`, | ||
ExpectError: regexp.MustCompile("monotonic validation can only be specified for number types, not string types"), | ||
}, { | ||
Name: "ValidationRegexMissingError", | ||
Config: ` | ||
|
@@ -424,6 +440,54 @@ data "coder_parameter" "region" { | |
require.Equal(t, expected, state.Primary.Attributes[key]) | ||
} | ||
}, | ||
}, { | ||
Name: "NumberValidation_MonotonicWithOptions", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used to drop an example here as well. |
||
Config: ` | ||
data "coder_parameter" "region" { | ||
name = "Region" | ||
type = "number" | ||
description = <<-EOF | ||
Always pick a larger region. | ||
EOF | ||
default = 1 | ||
|
||
option { | ||
name = "Small" | ||
value = 1 | ||
} | ||
|
||
option { | ||
name = "Medium" | ||
value = 2 | ||
} | ||
|
||
option { | ||
name = "Large" | ||
value = 3 | ||
} | ||
|
||
validation { | ||
monotonic = "increasing" | ||
} | ||
} | ||
`, | ||
Check: func(state *terraform.ResourceState) { | ||
for key, expected := range map[string]any{ | ||
"name": "Region", | ||
"type": "number", | ||
"validation.#": "1", | ||
"option.0.name": "Small", | ||
"option.0.value": "1", | ||
"option.1.name": "Medium", | ||
"option.1.value": "2", | ||
"option.2.name": "Large", | ||
"option.2.value": "3", | ||
"default": "1", | ||
"validation.0.monotonic": "increasing", | ||
} { | ||
require.Equal(t, expected, state.Primary.Attributes[key]) | ||
} | ||
}, | ||
}, { | ||
Name: "NumberValidation_Min", | ||
Config: ` | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice trick!