-
Notifications
You must be signed in to change notification settings - Fork 232
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
Support the pseudo dynamic type #248
Comments
An example that could be replaced with dynamic: https://www.terraform.io/docs/providers/aws/r/iam_policy.html#example-usage resource "aws_iam_policy" "policy" {
name = "test_policy"
path = "/"
description = "My test policy"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:Describe*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
} Could be: resource "aws_iam_policy" "policy" {
name = "test_policy"
path = "/"
description = "My test policy"
policy = {
Version = "2012-10-17"
Statement = [
{
Action = ["ec2:Describe*"]
Effect = "Allow"
Resource = "*"
}
]
} Or even: resource "aws_iam_policy" "policy" {
name = "test_policy"
path = "/"
description = "My test policy"
policy = jsondecode(<<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:Describe*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
)
} |
I am definitely interested in this great feature! I have a few requirements out of an internal provider I'm writing to house what can be generic JSON passed to an API, similar to the generality of IAM policies! 😄 I'm currently doing the opposite of the JSON decode here, encoding HCL any type into a String for the provider to pass to an API. |
@paultyng So I suppose we have to stick to serializing nested content via e.g. Do you have any idea approximately when milestone |
At the moment Terraform SDK does not support nested dynamic types, which are used by vRA API. Issue tracking development of this feature is on GitHub hashicorp/terraform-plugin-sdk#248 Workaround for this issue is added based on other providers such as AWS and IAM Policy resource https://www.terraform.io/docs/providers/aws/r/iam_policy.html#example-usage. Support is only added for `deployment_configuration`, `resource_configuration` is untouched. It is added to support nested structures in `deployment_configuration', especially arrays, which are necessary for some resources to operate. Signed-off-by: Maciej Karaś <[email protected]>
At the moment Terraform SDK does not support nested dynamic types, which are used by vRA API. Issue tracking development of this feature is on GitHub hashicorp/terraform-plugin-sdk#248 Workaround for this issue is added based on other providers such as AWS and IAM Policy resource https://www.terraform.io/docs/providers/aws/r/iam_policy.html#example-usage. Support is only added for `deployment_configuration`, `resource_configuration` is untouched. It is added to support nested structures in `deployment_configuration', especially arrays, which are necessary for some resources to operate. Signed-off-by: Maciej Karaś <[email protected]>
At the moment Terraform SDK does not support nested dynamic types, which are used by vRA API. Issue tracking development of this feature is on GitHub hashicorp/terraform-plugin-sdk#248 Workaround for this issue is added based on other providers such as AWS and IAM Policy resource https://www.terraform.io/docs/providers/aws/r/iam_policy.html#example-usage. Support is only added for `deployment_configuration`, `resource_configuration` is untouched. It is added to support nested structures in `deployment_configuration', especially arrays, which are necessary for some resources to operate. Signed-off-by: Maciej Karaś <[email protected]>
* Added support for nested JSON value At the moment Terraform SDK does not support nested dynamic types, which are used by vRA API. Issue tracking development of this feature is on GitHub hashicorp/terraform-plugin-sdk#248 Workaround for this issue is added based on other providers such as AWS and IAM Policy resource https://www.terraform.io/docs/providers/aws/r/iam_policy.html#example-usage. Support is only added for `deployment_configuration`, `resource_configuration` is untouched. It is added to support nested structures in `deployment_configuration', especially arrays, which are necessary for some resources to operate. Signed-off-by: Maciej Karaś <[email protected]>
@MaciejKaras we are looking to exposing this in 2.x (not 2.0), but we are probably months out for a solution for it right now if that helps you to decide, until then, yes I think the best approach is still to use typed HCL and |
I have another usecase for this feature, also from the AWS Provider: The resource type resource "aws_codepipeline" "example" {
# ...
stage {
name = "Source"
# ...
action {
# ...
provider = "GitHub"
configuration = {
Owner = "lifesum-terraform"
Repo = "test"
Branch = "master"
OAuthToken = var.github_token # This field will be settable starting in v3.0 of the AWS provider
}
}
}
} The values accepted by For v3.0 of the provider, we're making the whole We would still need to define the concrete types, but having them be selected by the value of For example: resource "aws_codepipeline" "example" {
# ...
stage {
name = "Source"
# ...
action {
# ...
provider = "GitHub"
configuration = {
owner = "lifesum-terraform"
repo = "test"
branch = "master"
oauth_token = var.github_token # This field would be Sensitive, the others wouldn't
}
}
}
stage {
name = "Build"
action {
# ...
provider = "CodeBuild"
configuration = {
project_name = "test"
environment_variable { # These could be structured in HCL, rather than collapsed as a string
name = "EXAMPLE_1"
value = "VALUE_1"
type = "PLAINTEXT"
}
environment_variable {
name = "EXAMPLE_2"
value = "example/parameter_2"
type = "PARAMETER_STORE"
}
}
}
}
} |
@paultyng with the introduction of terraform-plugin-go, I'm inclined to call this complete. It's not easy to use, but it's possible. Making it easier to use (by creating higher-level abstractions) I think is work that is ongoing, but that work is not specifically about exposing DynamicPseudoType. There's an argument to be made for leaving this open until it's surfaced in the helper/schema package, but I don't know that we have any intention of doing that. With all that being said, I'm going to close the issue out, but people should feel free to comment if they think it needs to be reopened; just make your case in the comment. :) |
@paddycarver awesome, glad to hear it's possible! Is there any API docs, or code blocks that you could link here as an artifact? I haven't gotten a chance yet to play around, but so far I've seen these: |
Hey @skylerto, Apologies, our examples are fairly lacking and the library assumes a lot of familiarity with Terraform's protocol. I can't give you a full end-to-end example, but let's see if I can give you the gist: First, assume we're returning the schema for a resource. Let's go ahead and define that schema. In terraform-plugin-go, a schema is a schema := map[string]tftypes.Type{
"name": tftypes.String,
"data": tftypes.DynamicPseudoType,
} Then the user may specify a config like: resource "my_resource" "foo" {
name = "my-name"
data = {
"some": ["arbitrary", 123, "data", false, "here"],
}
} or whatever. Literally anything that can be assigned to a variable can be used as the value for Then in the provider, maybe in the ApplyResourceChange RPC handler, you'll have code like this: value, err := req.Config.Unmarshal(schema)
if err != nil {
// return error
}
var conf map[string]tftypes.Value
err = value.As(&conf)
if err != nil {
// return error
} Now switch {
case conf["data"].Is(tftypes.Object{}):
var data map[string]tftypes.Value
err := conf["data"].As(&data)
if err != nil {
// return error
}
case conf["data"].Is(tftypes.String):
var data string
err := conf["data"].As(&data)
if err != nil {
return err
}
} I don't know if that helps at all, but the fundamental idea is that you get the When specifying provider-supplied data, a DynamicPseudoType just means any kind of value is acceptable in the response, just supply the value like any other, no need for special handling. Does that help at all? Sorry, all that code was typed in a GitHub comment box, so I apologise for typos and errors. |
Extremely helpful @paddycarver, thank you so much! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Tracking issue for adding DynamicPseudoType type support.
The text was updated successfully, but these errors were encountered: