Terraform - data source config json examples

Hi Team,

Does anyone have experience/examples of the json for each data source?
The data source creates, but is missing the config e.g. ClientId

e.g.

resource “squaredup_datasource” “m365” {
display_name = var.m365_data_source_name
data_source_name = var.m365_data_source_name

config = jsonencode({
** azureTenantId = var.azuretenantid**
** azureClientId = var.azureclientid**
** azureClientSecret = data.azurerm_key_vault_secret.azure_client_secret.value**
})
}

1 Like

Hi,
If you’re configuring Microsoft Office 365, you can use the following:

resource "squaredup_datasource" "prod_o365" {
  display_name     = "Production Microsoft 365"
  data_source_name = "Microsoft 365"
  config = jsonencode({
    intune            = "intune" // Adds Intune support
    authType          = "clientCreds"
    intuneImportUsers = true // Imports user objects to the graph
    tenantId          = var.tenant_id
    clientId          = var.prod_o365_read_only_client_id
    clientSecret      = var.prod_o365_read_only_client_secret
  })
}
2 Likes

You don’t happen to have an example for Web API?

What I have so far…

resource “squaredup_datasource” “azure_api” {
display_name = “Azure API”
data_source_name = “Web API”

config = jsonencode({
baseUrl = var.api_base_url
authentication = {
type = “oauth2-client-credentials”
sendCredentialsIn = “body”
tokenUrl = var.api_token_url
clientId = var.azureclientid
clientSecret = data.azurerm_key_vault_secret.azure_client_secret.value
scope = var.api_authorization_scope
}
})

Hi Zafar,

Dave Clarke - one of the PMs at SquaredUp here. I’ve raised a feature request to allow you to easily copy the data source config via the UI easily - that should at least give you a template to start working from! That will be released in the next couple of days.

In the meantime, here’s an example Web API config that might get you going:

jsonencode({
  baseUrl                  = "https://swapi.py4e.com/api/"
  authMode                 = "none"
  ignoreCertificateErrors  = false
  queryArgs = [
    {
      key             = "queryParameter"
      value           = "123"
    }
  ]
  headers = [
    {
      key             = "header"
      value           = "abc"
    }
  ]
})

I hope that helps!

@zafar.raza It’s now possible to copy the (JSON) config of a data source with just a click. When creating, or editing an existing, data source select […] → Copy JSON configuration to copy the current configuration. Give it a try and let me know if it helps!