Support for configuring blocks with optional parameters in attributes-as-blocks mode#244
Conversation
…-as-blocks mode Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
|
I checked if the I have gathered statistics showing which fields are working in this mode: AWS:
Azure:
So, the usage of this mode does not seem very common. However, we also cannot say the occurrence rate is very low for example, Azure provider. Since there is no automatic solution to this problem, the resources will need to be configured for the solution. At this point, it can be discussed how to handle the configuration. My proposal is to manipulate the schema during resource configurations and mark/set the fields that work in this mode with their correct values. Thus, the change on the terrajet side can be used in its current form. At the same time, the size and complexity of the change will be very minimal. Example usage of my proposal while resource configuration: |
|
@sergenyalcin Thank you for that impact analysis! I think your proposal looks promising but it'd also mean that we can't move to CLI schema representation in the builder. I looked at the reverse conversion function here and it seems like TF CLI does some things depending on the config mode. Have you had the chance to look at that to see if there is anything we can derive the config mode? |
I checked this code block. As you said that in this function, there are some things depending on the When we check this code block in details, when the value of
In other words, we see that the work done according to the For example, if the schema element is a map and the schema's Elem is a Resource object, the same function is called. So I'm not sure it's very possible to derive ConfigMode from the results in the generated schema. Please write if I'm missing a point.
I got your point. So we may need to consider another configuration option to handle this problem. For example, while doing manuel configuration, the relevant fieldPath value can be passed for a configuration option, and we can check this fieldPath in builder.go instead of checking the ConfigMode value. |
|
@sergenyalcin @muvaf just opened a fix/change setting |
| if sch.ConfigMode == schema.SchemaConfigModeAttr { | ||
| asBlocksMode = true | ||
| } | ||
| paramType, obsType, err := g.buildResource(et, cfg, tfPath, xpPath, asBlocksMode, names...) |
There was a problem hiding this comment.
The number of parameters that this method takes is annoying but given that we would refactor this part soon that should be fine for now.
|
Successfully created backport PR #254 for |
Description of your changes
Fixes #232
With this PR, configuring blocks with optional parameters will be possible. In terraform schemas, this logic works with a field:
ConfigMode. If the value of theConfigModefield isSchemaConfigModeAttr, we have to provide values for all options. Please see the details: https://stackoverflow.com/questions/69079945/terraform-inappropriate-value-for-attribute-ingress-while-creating-sg/69080432#69080432Reference document: https://www.terraform.io/language/attr-as-blocks
In this PR, a new check was added for tfTag. If the parent field is in the
SchemaConfigModeAttr, theomitemptytag is deleted from tftags of subfields.I have:
make reviewableto ensure this PR is ready for review.backport release-x.ylabels to auto-backport this PR if necessary.How has this code been tested
This PR was tested in provider-jet-aws side by provisioning, updating and deleting SecurityGroup resource. In tests the manifest was used:
Please see the original issue in jet-aws side: crossplane-contrib/provider-jet-aws#157