Skip to content
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

Merged
merged 5 commits into from
Dec 14, 2023
Merged

dataapiv2: More terraform v2 fixes #3463

merged 5 commits into from
Dec 14, 2023

Conversation

mbfrahry
Copy link
Member

@mbfrahry mbfrahry commented Dec 7, 2023

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

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a 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 👍

Comment on lines 76 to 82
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
}
Copy link
Contributor

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:

Suggested change
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):

  1. The Data API's SDK - so that this value can be used in the different tools.
  2. The Terraform Generator - so that we know how to process this type.
  3. The Data API / here - so that we know how this should be represented on disk.
  4. The Importers (both importer-rest-api-specs and importer-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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good shout! Done!

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@mbfrahry mbfrahry merged commit 983a3c9 into main Dec 14, 2023
2 checks passed
@mbfrahry mbfrahry deleted the more-terraform-v2-fixes branch December 14, 2023 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants