-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
azurerm_static_site_custom_domain
- make validation_type
optional
#15849
Merged
tombuildsstuff
merged 1 commit into
main
from
static_site_custom_domain_validation_type
Jun 29, 2022
+4
−1
Merged
Changes from all commits
Commits
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 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
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.
rather than doing this - we should instead update the Import function to set this field based on the value from the config
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.
@tombuildsstuff During the import, you don't have access to the config (i.e.
d.GetRawConfig
returns a cty value whose internal value isnil
). Also, this is the same case forterraform-plugin-framework
, where thetfsdk.ImportResourceStateRequest
only export the identifier which users have specified in the CLI. If we change the resource id into form like<azure resource id>:<validation type>
, then it should work. However, this seems weired.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.
@magodo we do this just fine in some other resources, it depends what's in the config at the time of import, as such it'll need to be defaulted but can override from the config as needed
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.
I'm assuming you mean this. But if I have following import code:
And have following config in the workspace:
Then inspect at the last line of the
Importer
, I get: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.
Unsure what the status is here, reading the config while importing isn't possible then?
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.
@fvdnabee Yes, for the terraform framwork SDK, it is clearly documented: https://www.terraform.io/plugin/framework/resources#read (read is similar to import)
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.
Thank you for that link @magodo, reading the tf config during import appears to be documented as unsupported indeed.
Considering
validation_type
is not part of the state of the SWA customDomain Azure resource state [1], should it be tracked as part of the terraform state? Couldn't it be removed from the TF state altogether?Once the domain is available, it seems irrelevant whether it was validated via a CNAME record or TXT record (and Azure appears to not be tracking the validation_type; see [1]). If the domain validation fails, then the custom domain resource fails to be created; so on the next tf apply it would be recreated and the provider can just read the validation_type from the config again. validation_type also does not seem to impact resource destruction. Maybe the validation type can just be read from the config when creating/updating the resource and it could be removed from the tf state? I'm unsure if this is feasible in the provider however.
[1] this is what azurerm returns for an active custom domain; note the validation type is not tracked:
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.
@fvdnabee Thanks for the clarification! Given the
validation_type
is not returned in GET, hence we didn't set it to state in read. In case the custom domain is created via Terraform, it is still set in the state during create as it is in the config. On the other hand, if it is imported, then the state will never havevalidation_type
, which means you shouldn't specify it in the config as well, to avoid the diff.That said, the
validation_type
is only useful during creation, and should be ignored in other cases. So one solution is to make thevalidation_type
optional, but still mark it as required in the document to indicate that it is required during create, as this PR did. Another way to workaround this is to use theignore_chanages
to explicitly ignore it after you imported it.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.
@magodo could you clarify the following:
This is a necessary requirement for terraform providers? Including the validation type in the resource creation request forces us to track it as part of the TF state? I understand it is impossible (or bad practice?) to include parameters in the resource creation request that are sourced from the TF config without them being tracked in the TF state?
I like the optional
validation_type
idea for importing (then it wouldn't be part of the TF state), but when creating a custom domain resourced it should indeed be clear thatvalidation_type
is a required argument. Is it possible to enforce this in the provider (i.e.validation_type
must be specified when creating the resource; ifvalidation_type
is absent during creation the provider throws an error)?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.
Yes, provider will fail if
validation_type
is not set in creation.For the reason why it is set in the state during creation, it is how the plugin SDKv2 works. The values in the config will be in the state if don't explicitly change them.