Damo
Damo

Reputation: 2070

Update DNS Zone in different resource group using BICEP

I need up update a DNS Zone during a BICEP deployment. The zone already exists in another resource group.

I know I should be able to pull an existing resource in a different RG, but the methods I try do not work.

Method 1:

This reports error

"A resource's computed scope must match that of the Bicep file for it to be deployable. This resource's scope is computed from the "scope" property value assigned to ancestor resource "zone". You must use modules to deploy resources to a different scope.bicep(BCP165)"

resource zone 'Microsoft.Network/dnsZones@2023-07-01-preview' existing = {
  name: 'xxxx-xxxx.com'  
  scope:resourceGroup('xxxx-Bicep-xxxx-Deploy1')
}

resource record 'Microsoft.Network/dnsZones/CNAME@2023-07-01-preview' = {
  name: 'cname update'
  parent: zone
  properties: {
    TTL: 1200
    CNAMERecord:{
      cname:'record'
    }
  }  
}

So I used a module.

Method 2:

This reports error:

This expression is being used in an assignment to the "parent" property of the "Microsoft.Network/dnsZones/CNAME" type, which requires a value that can be calculated at the start of the deployment. Properties of getthezone which can be calculated at the start include "name".bicep(BCP120)

File 1

module getthezone 'getdnszone.bicep' = {
  name: 'zoneget'
}

resource record 'Microsoft.Network/dnsZones/CNAME@2023-07-01-preview' = {
  name: 'cname update'
  parent: getthezone.outputs.thezone
  properties: {
    TTL: 1200
    CNAMERecord:{
      cname:'tuemp'
    }
  }  
}

File 2

resource zone 'Microsoft.Network/dnsZones@2023-07-01-preview' existing = {
  name: 'xxx-xxxx.xxx'  
  scope:resourceGroup('xxxx-Bicep-xxxx-Deploy1')
}

output thezone object = zone

If I change the output from file 2 to string and use that, I get error:

This expression is being used in an assignment to the "parent" property of the "Microsoft.Network/dnsZones/CNAME" type, which requires a value that can be calculated at the start of the deployment. Properties of getthezone which can be calculated at the start include "name".bicep(BCP120)

I'm missing something. How can I update a DNS record in another resource group using BICEP?

Upvotes: 0

Views: 1089

Answers (1)

GordonBy
GordonBy

Reputation: 3407

Try this.

file 1

module dothezone 'dothezone.bicep' = {
  name: 'zoneget'
  scope:resourceGroup('xxxx-Bicep-xxxx-Deploy1')
}

File 2

resource zone 'Microsoft.Network/dnsZones@2023-07-01-preview' existing = {
  name: 'xxx-xxxx.xxx'  
}

resource record 'Microsoft.Network/dnsZones/CNAME@2023-07-01-preview' = {
  name: 'cname update'
  parent: zone
  properties: {
    TTL: 1200
    CNAMERecord:{
      cname:'tuemp'
    }
  }  
}

Upvotes: 2

Related Questions