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

New Resource: azurerm_iothub #887

Merged
merged 73 commits into from
Mar 15, 2018
Merged

Conversation

shelleybess
Copy link
Contributor

Add IotHub resource to provider.

girishramnani and others added 30 commits September 28, 2017 11:49
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)
Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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!

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.

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!

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSubnetDestroy,
Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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?

@@ -359,6 +359,17 @@
</ul>
</li>

<li<%= sidebar_current("docs-azurerm-resource-iothub") %>>
<a href="#">IotHub Resources</a>
Copy link
Contributor

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?

Copy link
Contributor Author

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.


* `id` - The IotHub ID.

* `etag` - The etag of IotHub Resource.
Copy link
Contributor

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

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.

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()
Copy link
Contributor

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
Copy link
Contributor

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)
}
Copy link
Contributor

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)
Copy link
Contributor

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) {
Copy link
Contributor

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?

setUserAgent(&ihrc.Client)
ihrc.Authorizer = auth
ihrc.Sender = sender
ihrc.SkipResourceProviderRegistration = c.skipProviderRegistration
Copy link
Contributor

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)

"revision": "8c58b4788dedd95779efe0ac2055bb6a1b9b8e01",
"revisionTime": "2018-01-06T16:29:27Z",
"revision": "1e3943ee722538420f21945f4bc820347abe433d",
"revisionTime": "2018-02-15T17:42:55Z",
"version": "v9.7.0",
"versionExact": "v9.7.0"
Copy link
Contributor

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)

"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"
Copy link
Contributor

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

"purpose" = "testing"
}
}

Copy link
Contributor

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?


* `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`.
Copy link
Contributor

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"

@tombuildsstuff tombuildsstuff self-assigned this Mar 14, 2018
@tombuildsstuff
Copy link
Contributor

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!

@tombuildsstuff tombuildsstuff changed the title WIP: New resource azurerm_iothub New resource azurerm_iothub Mar 14, 2018
@tombuildsstuff tombuildsstuff changed the title New resource azurerm_iothub New Resource: azurerm_iothub Mar 14, 2018
@shelleybess
Copy link
Contributor Author

@tombuildsstuff

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

@tombuildsstuff
Copy link
Contributor

hey @shelleybess

That's great, thank you! I don't mind at all. I'm sorry I haven't had time to wrap that up.

No worries at all :)

The deletion of IoTHub is still timing out. I have not made any changes to that yet.

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!

@tombuildsstuff
Copy link
Contributor

Tests pass:

screen shot 2018-03-14 at 21 44 14

@tombuildsstuff tombuildsstuff modified the milestones: 1.3.0, 1.3.1 Mar 15, 2018
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 with the latest changes 👍 - thanks for this!

@tombuildsstuff tombuildsstuff merged commit 10309b8 into hashicorp:master Mar 15, 2018
tombuildsstuff added a commit that referenced this pull request Mar 15, 2018
@ghost
Copy link

ghost commented Mar 31, 2020

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!

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants