Skip to content

Commit c95cb5f

Browse files
fix terraform identity resource format (#81)
fixes #80 This PR fixes the `parent_id` and `identity` format in the azapi resource format. --------- Co-authored-by: Anthony Martin <[email protected]>
1 parent 982ebbd commit c95cb5f

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

src/TemplateRefGenerator.Tests/Files/markdown/microsoft.addons/2018-03-01/supportproviders/supportplantypes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ To create a Microsoft.Addons/supportProviders/supportPlanTypes resource, add the
9696
resource "azapi_resource" "symbolicname" {
9797
type = "Microsoft.Addons/supportProviders/supportPlanTypes@2018-03-01"
9898
name = "string"
99+
parent_id = "string"
99100
}
100101
```
101102
## Property Values

src/TemplateRefGenerator.Tests/Files/markdown/microsoft.compute/2024-03-02/disks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ To create a Microsoft.Compute/disks resource, add the following Terraform to you
629629
resource "azapi_resource" "symbolicname" {
630630
type = "Microsoft.Compute/disks@2024-03-02"
631631
name = "string"
632+
parent_id = "string"
632633
location = "string"
633634
tags = {
634635
{customized property} = "string"

src/TemplateRefGenerator.Tests/Files/markdown/microsoft.documentdb/2024-05-15/databaseaccounts.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ The following [Azure Verified Modules](https://aka.ms/avm) can be used to deploy
426426
> | Module | Description |
427427
> | ----- | ----- |
428428
> | [CosmosDB Database Account](https://github.com/Azure/bicep-registry-modules/tree/main/avm/res/document-db/database-account) | AVM Resource Module for CosmosDB Database Account |
429-
429+
430430
### Azure Quickstart Samples
431431

432432
The following [Azure Quickstart templates](https://aka.ms/azqst) contain Bicep samples for deploying this resource type.
@@ -880,12 +880,12 @@ To create a Microsoft.DocumentDB/databaseAccounts resource, add the following Te
880880
resource "azapi_resource" "symbolicname" {
881881
type = "Microsoft.DocumentDB/databaseAccounts@2024-05-15"
882882
name = "string"
883-
identity = {
883+
parent_id = "string"
884+
identity {
884885
type = "string"
885-
userAssignedIdentities = {
886-
{customized property} = {
887-
}
888-
}
886+
identity_ids = [
887+
"string"
888+
]
889889
}
890890
location = "string"
891891
tags = {

src/TemplateRefGenerator.Tests/Files/markdown/microsoft.keyvault/2023-07-01/vaults.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ To create a Microsoft.KeyVault/vaults resource, add the following Terraform to y
484484
resource "azapi_resource" "symbolicname" {
485485
type = "Microsoft.KeyVault/vaults@2023-07-01"
486486
name = "string"
487+
parent_id = "string"
487488
location = "string"
488489
tags = {
489490
{customized property} = "string"

src/TemplateRefGenerator.Tests/Files/markdown/microsoft.resources/2024-07-01/resourcegroups.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ To create a Microsoft.Resources/resourceGroups resource, add the following Terra
208208
resource "azapi_resource" "symbolicname" {
209209
type = "Microsoft.Resources/resourceGroups@2024-07-01"
210210
name = "string"
211+
parent_id = "string"
211212
location = "string"
212213
tags = {
213214
{customized property} = "string"

src/TemplateRefGenerator/Generators/CodeSampleGenerator.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,18 @@ void AddProperty(string name, Action writeValue)
364364
AddProperty("type", () => sb.Append($"\"{resource.ResourceType}@{resource.ApiVersion}\""));
365365
AddProperty("name", () => sb.Append($"\"string\""));
366366

367-
if (resource.Type.ScopeType == ScopeType.Unknown ||
368-
resource.Type.ScopeType.HasFlag(ScopeType.Extension))
367+
AddProperty("parent_id", () => sb.Append($"\"string\""));
368+
369+
if (props.FirstOrDefault(x => x.Key == "identity") is {} identityProp && identityProp.Key != null)
369370
{
370-
AddProperty("parent_id", () => sb.Append($"\"string\""));
371+
props.Remove(identityProp);
372+
sb.AppendLine($"{propIndent}identity {{");
373+
var nestedPropIndent = GetIndent(indentLevel + 2);
374+
sb.AppendLine($"{nestedPropIndent}type = \"string\"");
375+
sb.AppendLine($"{nestedPropIndent}identity_ids = [");
376+
sb.AppendLine($"{nestedPropIndent}{GetIndent(1)}\"string\"");
377+
sb.AppendLine($"{nestedPropIndent}]");
378+
sb.AppendLine($"{propIndent}}}");
371379
}
372380
}
373381

0 commit comments

Comments
 (0)