-
Notifications
You must be signed in to change notification settings - Fork 57
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
dataapiv2: More terraform v2 fixes #3463
Conversation
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.
We need to update the Terraform Schema Field Type to return an error if the mapping isn't defined rather than passing this value through (as we do for Object Definition Types) - but if we can fix that up then this otherwise LGTM 👍
output.Type = models.TerraformSchemaFieldType(input.Type) | ||
|
||
// Type could have been modified from the importer-rest-api-specs and will need to be mapped back to what it was originally. | ||
// we'll overwrite what is in output.Type if the value exists in terraformSchemaObjectDefinitionToTerraformFieldSchemaTypes | ||
if mapped, ok := terraformSchemaObjectDefinitionToTerraformFieldSchemaTypes[input.Type]; ok { | ||
output.Type = mapped | ||
} |
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.
If the value doesn't exist in this map then we're not going to know how to handle it downstream (e.g. in the Generators) - so we'd want to raise an error if this doesn't exist in the map:
output.Type = models.TerraformSchemaFieldType(input.Type) | |
// Type could have been modified from the importer-rest-api-specs and will need to be mapped back to what it was originally. | |
// we'll overwrite what is in output.Type if the value exists in terraformSchemaObjectDefinitionToTerraformFieldSchemaTypes | |
if mapped, ok := terraformSchemaObjectDefinitionToTerraformFieldSchemaTypes[input.Type]; ok { | |
output.Type = mapped | |
} | |
mapped, ok := terraformSchemaObjectDefinitionToTerraformFieldSchemaTypes[input.Type] | |
if !ok { | |
return nil, fmt.Errorf("internal-error: missing mapping for Terraform Schema Field Type %q", string(input.Type)) | |
} | |
output.Type = mapped |
This ensures that when a new Terraform Schema Field Type is added that we're able to ensure that it's supported in (in order):
- The Data API's SDK - so that this value can be used in the different tools.
- The Terraform Generator - so that we know how to process this type.
- The Data API / here - so that we know how this should be represented on disk.
- The Importers (both
importer-rest-api-specs
andimporter-msgraph-metadata
, in the future) - so that we can enable this.
This approach allows us to gradually add support for a new Terraform Schema Field Type such whilst leaving the pipeline working throughout - meaning that we only expose a new Terraform Schema Field Type once it's fully supported - and gives us a quick means of disabling this for debugging purposes to unblock the pipeline if there is an issue. (This is also the approach we use for the Object Definition Types fwiw)
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.
Good shout! Done!
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.
LGTM 👍
This PR should be the last of the Terraform fixes needed for the terraform generation to be 1-1.
There is one issue in that the ordering of ModelToModel mappings does not match the old data api model. This will cause differences when running the generator but it should only happen once. I don't see a way to get the ordering to match but if we really want 1-1 then it will require another set of eyes to figure it out