-1

I have added Send Grid API Key into App Settings as follows:

enter image description here

I have an ARM Template with resources element which includes the following:

"resources": [               
    {
       "apiVersion": "2016-08-01",
        "name": "appsettings",
        "type": "config",
        "dependsOn": [
          "[resourceId('Microsoft.Web/sites', variables('apiApp').name)]"
        ],
        "properties": {
           "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId(variables('dataResourceGroup').name, 'Microsoft.Insights/components', variables('dataAppInsights').name), '2014-04-01').InstrumentationKey]",
           "apiClientId": "[parameters('apiAppId')]",
           "prereqsKeyVaultName": "[concat(parameters('solutionAbbreviation'), '-prereqs-', parameters('environmentAbbreviation'))]",
           "dataKeyVaultName": "[concat(parameters('solutionAbbreviation'), '-data-', parameters('environmentAbbreviation'))]"
         }
     }
]

How do I add SENDGRID_APIKEY into ARM Template and use that in the program shown below?

    private static void Main()
    {
        Execute().Wait();
    }
    static async Task Execute()
    {
        var apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY");
        var client = new SendGridClient(apiKey);
        var from = new EmailAddress("abc.com", "ABC");
        var subject = "Testing SendGrid";
        var to = new EmailAddress("xyz.com", "XYZ"); 
        var plainTextContent = "This is a test";
        var htmlContent = "test";
        var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
        var response = await client.SendEmailAsync(msg);
    }
E_net4
  • 27,810
  • 13
  • 101
  • 139
user989988
  • 3,006
  • 7
  • 44
  • 91
  • 2
    Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange (SE) network, you've granted a non-revocable right, under the [CC BY-SA 3.0 license](//creativecommons.org/licenses/by-sa/3.0), for SE to distribute that content (i.e. regardless of your future choices). By SE policy, the non-vandalized version of the post is the one which is distributed. Thus, any vandalism will be reverted. If you want to know more about deleting a post please see: [How does deleting work? ...](https://meta.stackexchange.com/q/5221/271271) – Makyen Nov 19 '18 at 17:27

1 Answers1

1

I dont understand the question, just add it as another key\value pair?

"resources": [               
    {
       "apiVersion": "2016-08-01",
        "name": "appsettings",
        "type": "config",
        "dependsOn": [
          "[resourceId('Microsoft.Web/sites', variables('apiApp').name)]"
        ],
        "properties": {
           "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId(variables('dataResourceGroup').name, 'Microsoft.Insights/components', variables('dataAppInsights').name), '2014-04-01').InstrumentationKey]",
           "apiClientId": "[parameters('apiAppId')]",
           "prereqsKeyVaultName": "[concat(parameters('solutionAbbreviation'), '-prereqs-', parameters('environmentAbbreviation'))]",
           "dataKeyVaultName": "[concat(parameters('solutionAbbreviation'), '-data-', parameters('environmentAbbreviation'))]",
           "SENDGRIP_APIKEY": "somevalue"
         }
     }
]

if you want to dynamically pass it, add another parameter and reference that parameter like you do any other [parameters('sendgrid')]

4c74356b41
  • 69,186
  • 6
  • 100
  • 141