-
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 Resource: azurerm_iothub
#887
Conversation
As the refresh function ( read lifecyle ) of the iothub resource is only dependent on the id of the resource to genarate the state StatePassthrough method is used
Signed-off-by: shelley.bess <shelley.bess@vertivco.com>
return nil | ||
} | ||
|
||
return fmt.Errorf("Error waiting for the deletion of IoTHub %q", iotHubName) |
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.
There is a timeout issue here. IoTHub is deleted in Azure, but terraform times out with an error destroying resource.
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.
so this timeout is configured in the client initialisation above: https://github.com/terraform-providers/terraform-provider-azurerm/pull/887/files/3e927a6d96d0c91b3dc132d9b9e83f4b1fc96650#diff-848235249455ee48aaf3ea5d431960aeR597
we can actually swap that out for this function:
https://github.com/terraform-providers/terraform-provider-azurerm/blob/master/azurerm/config.go#L435
which sets a 60m polling timeout, which should solve this issue. There's a separate task to move everything over to that at some point, but any changes to azure/config.go
cause merge conflicts, so we're trying to do it piecemeal rather than bit by bit
Hope that helps :)
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.
This is very helpful, thank you!
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 @shelleybess
Thanks for pushing those updates (and for fixing the rebase issues) - I've taken a look through and left some updated comments in-line :)
Thanks!
azurerm/import_arm_iothub_test.go
Outdated
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMSubnetDestroy, |
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.
can we update this to be testCheckAzureRMIotHubDestroy
?
return err | ||
} | ||
|
||
if !*res.NameAvailable { |
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.
will this fail when updating a resource?
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.
It updates the resource correctly. I want to add an accTest for this as well.
desc.Tags = *expandTags(tags) | ||
} | ||
|
||
future, err := iothubClient.CreateOrUpdate(ctx, rg, name, desc, updateIoT) |
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.
so we should be able to submit an empty string rather than retrieving the eTag here (since Terraform's plan will show the user what will be done)
return fmt.Errorf("Error flattening `shared_access_policy` in IoTHub %q: %+v", iothubName, err) | ||
} | ||
|
||
d.Set("shared_access_policy", keys) |
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.
can we sort the ordering on these four lines, I think this should be:
if err := d.Set("shared_access_policy", keys); err != nil {
return fmt.Errorf("...")
}
d.Set("shared_access_policy", keys) | ||
d.Set("hostname", properties.HostName) | ||
d.Set("type", desc.Type) | ||
flattenAndSetTags(d, &desc.Tags) |
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.
can we also set the sku
block? This should be returned as part of the properties object
func testCheckAzureRMIotHubDestroy(s *terraform.State) error { | ||
ctx := testAccProvider.Meta().(*ArmClient).StopContext | ||
|
||
conn := testAccProvider.Meta().(*ArmClient).expressRouteCircuitClient |
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 think this wants to be using iothubResourceClient
?
"purpose" = "testing" | ||
} | ||
} | ||
`, rInt, location, rInt) |
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.
really minor could we sort the spacing out here?
website/azurerm.erb
Outdated
@@ -359,6 +359,17 @@ | |||
</ul> | |||
</li> | |||
|
|||
<li<%= sidebar_current("docs-azurerm-resource-iothub") %>> | |||
<a href="#">IotHub Resources</a> |
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.
🤔 do you think it'd make sense for this to live under the Messaging Resources
block?
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 agree. It shouldn't have its own block.
website/docs/r/iothub.html.markdown
Outdated
|
||
* `id` - The IotHub ID. | ||
|
||
* `etag` - The etag of IotHub Resource. |
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.
minor could we remove this since it's now no longer being exposed
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 @shelleybess
Thanks for pushing those updates - I've taken a look through and left a few more comments in-line, but this is really close now. The two main things left to fix are ensuring we set all of the fields, and re-vendoring v12.5.0-beta
of the Azure SDK for Go - otherwise this is looking pretty good :)
Thanks!
} | ||
|
||
keysResp, err := iothubClient.ListKeys(ctx, id.ResourceGroup, iothubName) | ||
keyList := keysResp.Response() |
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.
can we check the error returned here?
|
||
future, err := iothubClient.CreateOrUpdate(ctx, rg, name, desc, "") | ||
if err != nil { | ||
return err |
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.
can we wrap this error to be more descriptive with what went wrong:
return fmt.Errorf("Error creating IoTHub %q (Resource Group %q): %+v", err)
|
||
keyMap["permissions"] = string(key.Rights) | ||
keys = append(keys, keyMap) | ||
} |
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.
can we pull this out into a separate function flattenAzureIotSharedAccessPolicy
?
} | ||
|
||
d.Set("type", desc.Type) | ||
flattenAndSetTags(d, &desc.Tags) |
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.
so the Import test (TestAccAzureRMIotHub_importBasic
) currently fails due to the following fields not being set - can we set them:
location
name
resource_group_name
sku
capacity
name
tier
on that note - could we pull this out into a new flatten
function? I believe this should be what's needed to flatten the SKU block:
func flattenArmIoTHubSku(input *devices.IotHubSkuInfo) []interface {
sku := make(map[string]interface{}, 0)
if capacity := input.Capacity; capacity != nil {
sku["capacity"] = *capacity
}
if name := input.Name; name != nil {
sku["name"] = *name
}
if tier := input.Tier; tier != nil {
sku["tier"] = *tier
}
return []interface{}{result}
}
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccAzureRMIotHub_basicStandard(t *testing.T) { |
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.
minor can we split this into two tests - one _basic
without the SKU block, and one _complete
with it?
azurerm/config.go
Outdated
setUserAgent(&ihrc.Client) | ||
ihrc.Authorizer = auth | ||
ihrc.Sender = sender | ||
ihrc.SkipResourceProviderRegistration = c.skipProviderRegistration |
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 these 4 lines:
setUserAgent(&ihrc.Client)
ihrc.Authorizer = auth
ihrc.Sender = sender
ihrc.SkipResourceProviderRegistration = c.skipProviderRegistration
can we swap this over to using the newer style registration function? e.g.
c.configureClient(&ihrc.Client, auth)
vendor/vendor.json
Outdated
"revision": "8c58b4788dedd95779efe0ac2055bb6a1b9b8e01", | ||
"revisionTime": "2018-01-06T16:29:27Z", | ||
"revision": "1e3943ee722538420f21945f4bc820347abe433d", | ||
"revisionTime": "2018-02-15T17:42:55Z", | ||
"version": "v9.7.0", | ||
"versionExact": "v9.7.0" |
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.
taking a look into this - this is because SDKv14 is vendored in, downgrading to v12.5
should fix this for the moment (we'll upgrade in the near future)
vendor/vendor.json
Outdated
"checksumSHA1": "l4BaDOG5showWuLiGBjsY4eVhtk=", | ||
"path": "github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2017-07-01/devices", | ||
"revision": "1e334c402ea1460704b0263e5d188f28ad946ce1", | ||
"revisionTime": "2018-02-16T17:41:56Z" |
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.
can we vendor this using the v12.5.0-beta
tag? I believe that should mean we can downgrade to v10
of AutoRest too - you can do this via:
govendor update github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2017-07-01/devices@=v12.5.0-beta
website/docs/r/iothub.html.markdown
Outdated
"purpose" = "testing" | ||
} | ||
} | ||
|
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.
minor could we make the spacing consistent here by switching to use spaces instead of tabs?
website/docs/r/iothub.html.markdown
Outdated
|
||
* `name` - (Required) The name of the sku. Supports `F1`, `S1`, `S2`, and `S3`. | ||
|
||
* `tier` - (Required) The billing tier for the IoT Hub. `Free` or `Standard`. |
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.
can we make this "Possible values are free
or Standard
"
hey @shelleybess Thanks for pushing the latest set of updates - just to let you know that I'm going to push a few commits to fix the issues outlined above so that we can ship this as part of the v1.3.0 release of the AzureRM Provider; I hope you don't mind! Thanks! |
azurerm_iothub
azurerm_iothub
azurerm_iothub
azurerm_iothub
That's great, thank you! I don't mind at all. I'm sorry I haven't had time to wrap that up. The deletion of IoTHub is still timing out. I have not made any changes to that yet. Thank you :) |
hey @shelleybess
No worries at all :)
Thanks for confirming that - taking a look into this this appears to be a bug in the Azure SDK, which is coming from a badly defined Swagger document (since the Go SDK is generated) - as such I've opened this issue to get that fixed: Azure/azure-rest-api-specs#2661 In the interim we should be able to work around this by replacing the Delete waiter with a custom waiter (here's an example in the Template Deployment resource](https://github.com/terraform-providers/terraform-provider-azurerm/blob/master/azurerm/resource_arm_template_deployment.go#L266)) - I'll push a commit to add one (since I've got the branch checked out) 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.
LGTM with the latest changes 👍 - thanks for this!
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! |
Add IotHub resource to provider.