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

IoTHub Connection Strings #1743

Closed
szaroubi opened this issue Aug 8, 2018 · 7 comments · Fixed by #1789
Closed

IoTHub Connection Strings #1743

szaroubi opened this issue Aug 8, 2018 · 7 comments · Fixed by #1789

Comments

@szaroubi
Copy link
Contributor

szaroubi commented Aug 8, 2018

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

After provisioning an IoT Hub and an Azure Function, I would like to set a Function App setting (app_setting) with one of the IoTHub connection strings.

In order to accomplish this, one can generate the connection strings according to this document.
https://blogs.msdn.microsoft.com/iotdev/2017/05/09/understand-different-connection-strings-in-azure-iot-hub/

New or Affected Resource(s)

Not sure, don't know the codebase enough.

Potential Terraform Configuration

resource "azurerm_function_app" "main" {
  name                      = "iot-function-test"
  .
  .
  .
  app_settings{
    IoTHubConnectionString = "${azurerm_iothub.main.eventhubconnectionstring}
  }
}
@szaroubi
Copy link
Contributor Author

szaroubi commented Aug 9, 2018

If someone would like to point me in a technical direction, I would like to try to take a crack at it.

@tombuildsstuff
Copy link
Contributor

hey @szaroubi

Thanks for opening this issue / offering to contribute a fix for this :)

Whilst I've not checked the HTTP response, but I believe this should be available as the EventHubEndpoints value in the in properties field within this block - which returns a map[string]*EventHubProperties, which has an Endpoint property (which should be the connection string). It should be possible to add a new Computed (e.g. read-only) field to the schema which returns a list of EventHub Endpoints/Connection String - which will need mapping to an array of strings e.g.

connectionStrings := make([]string, 0)
for _, v := range properties.EventHubEndpoints {
  if v != nil && v.Endpoint != nil {
    connectionStrings = append(connectionStrings, *v.Endpoint)
  }
}

Given this is a complex object - I'd also recommend checking for errors when setting the object in the state too:

if err := d.Set("eventhub_connection_strings", connectionStrings); err != nil {
  return fmt.Errorf("Error flattening `eventhub_connection_strings`: %+v", err)
}

Hope that helps - please let us know if you have any other questions :)

Thanks!

@szaroubi
Copy link
Contributor Author

Hello @tombuildsstuff ,
Thank you for the very prompt reply.

Seeing I am a total n00b when it comes to building and running the terraform-provier-azurerm project.
Could I ask you to point me to some doc on how to set up my env ?

A part from the README.md file, is there other documentation on how to setup and test this provider (or other providers) with an existing terraform build (or generate a new terraform build)?

@szaroubi
Copy link
Contributor Author

Here is my PR: #1789

@tombuildsstuff
Copy link
Contributor

hey @szaroubi

Thanks for that PR - that's now been merged and will go out as part of the next release of the AzureRM Provider :)

Thanks!

@tombuildsstuff tombuildsstuff added this to the 1.14.0 milestone Aug 21, 2018
@tombuildsstuff
Copy link
Contributor

hey @szaroubi

Just to let you know that this has been released in v1.14.0 of the AzureRM Provider which is now available: https://github.com/terraform-providers/terraform-provider-azurerm/blob/v1.14.0/CHANGELOG.md

Thanks!

@ghost
Copy link

ghost commented Mar 6, 2019

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 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants