-
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
New data source 'azurerm_resources' #3529
Conversation
|
Tests pass.
@tombuildsstuff @katbyte, can you review this PR? |
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.
hey @tiwood
Thanks for this PR - apologies for the delayed review here, we've been chatting about this internally trying to work out what's needed to get this in.
On the whole this looks pretty good, however there's a few things that need adjusting before we can merge this; in particular Terraform Core has a limit on the size of a Resource's State, as such we'll need to ensure we filter to a subset of the resources in the subscription, rather than storing the lot to ensure we don't hit this limit. That said, if we can fix those up this is otherwise looking good to me 👍
Thanks!
@tombuildsstuff, thank you for the review. |
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.
hey @tiwood
Thanks for pushing those changes - taking a look through I noticed a few more minor issues but this otherwise LGTM 👍
Thanks!
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.
Thanks for the changes @tiwood,
However running it in our CI system it does seem like all the tests fail:
------- Stdout: -------
=== RUN TestAccDataSourceAzureRMResources_ByName
=== PAUSE TestAccDataSourceAzureRMResources_ByName
=== CONT TestAccDataSourceAzureRMResources_ByName
--- FAIL: TestAccDataSourceAzureRMResources_ByName (101.02s)
testing.go:569: Step 0 error: Check failed: Check 1/1 error: data.azurerm_resources.test: Attribute 'resources.#' expected "1", got "0"
FAIL
------- Stderr: -------
2019/10/09 17:03:03 [DEBUG] Registering Data Sources for "Compute"..
2019/10/09 17:03:03 [DEBUG] Registering Resources for "Compute"..
I've just seen this happening on my side too. It seems we have a replication lag issue here, the API sometimes returns no results. I can add a retry function to the data source or we can add a sleep to the test case (somehow?), but that dosen't sound right to me. |
🤔 given its a search index probably updating a retry in the resource makes less sense then a delay in the test steps. |
Any pointers how I could do that? I've added some code to account for the replication lag/indexing, which seems to work now: stateConf := &resource.StateChangeConf{
Pending: []string{"ResourcesNotFound"},
Target: []string{"ResourcesFound"},
Refresh: dataArmResourcesStateStatusCodeRefreshFunc(ctx, meta, filter),
Timeout: 2 * time.Minute,
MinTimeout: 30 * time.Second,
ContinuousTargetOccurence: 2,
}
func dataArmResourcesStateStatusCodeRefreshFunc(ctx context.Context, meta interface{}, filter string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
resourcesClient := meta.(*ArmClient).Resource.ResourcesClient
resp, err := resourcesClient.ListComplete(ctx, filter, "", nil)
if err != nil {
return nil, "", fmt.Errorf("Error while waiting for the resources to become available: %+v", err)
}
if resp.Value().ID == nil {
return resp, "ResourcesNotFound", nil
}
return resp, "ResourcesFound", nil
}
} |
Thanks! Give me a bit to discuss the best way forward internally and we'll get back to you 🙂 |
…ount for replication lag.
I've pushed the changes which include Please let me know if you want to put a delay in the tests rather than wait for state in the data source itself. |
hey @tiwood Thanks for pushing those changes. Taking a look through it appears the "replication issue" referred to above is a known issue in the test framework; where the Data Source will be called before the Resource has finished provisioning, unless there's an explicit
which means that the Resources will exist before the Data Source looks them up (we could also use a depends_on, but we're intentionally not since this is a test framework specific issue) When updating the code to account for this (and removing the WaitForState check) the tests pass:
Since I've made these changes locally to be able to confirm this I hope you don't mind but I'm going to push a commit with said change so that we can get this merged - but this otherwise LGTM 👍 Thanks! |
dismissing since changes have been pushed
This has been released in version 1.36.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example: provider "azurerm" {
version = "~> 1.36.0"
}
# ... other configuration ... |
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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks! |
This PR introduces the new data source 'azurerm_resources'.
This data source can be used to get a list of resources which match specified criteria.
All attributes can be combined to fine tune the results.
The resulting list can be used in subsequent resources.
Example Usage
Argument Reference
name
- (Optional) The name of the Resource.resource_group_name
- (Optional) The name of the Resource group where the Resources are located.type
- (Optional) The Resource Type of the Resources you want to list (e.g.Microsoft.Network/virtualNetworks
). A full list of available Resource Types can be found here.required_tags
- (Optional) A mapping of tags which the Resource has to have in order to be included in the result.Attributes Reference
resources
- One or moreresource
blocks as defined below.The
resource
block contains:name
- The name of this resource.id
- The Resource ID of this resource.type
- The type of this resoource.location
- The location of this resource.tags
- The type of resource that this is, such asMicrosoft.Network/virtualNetworks
.