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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip autonamed fields #122

Open
t0yv0 opened this issue Feb 27, 2024 · 0 comments
Open

Skip autonamed fields #122

t0yv0 opened this issue Feb 27, 2024 · 0 comments
Labels
kind/enhancement Improvements or new features

Comments

@t0yv0
Copy link
Member

t0yv0 commented Feb 27, 2024

Hello!

  • Vote on this issue by adding a 馃憤 reaction
  • If you want to implement this feature, comment to let us know (we'll work with you on design, scheduling, etc.)

Issue details

@iwahbe points out that switching to pulumi convert when rendering examples started generating autonamed Name: properties, where we have a slight preference to omit them as the idiomatic way is for Pulumi to automatically infer values for these. There seems to be some metadata indicating that a property is autonamed as shown below.

$ jq '.resources["azurerm_api_management_logger"]' azurerm.json                   
{
  "tok": "azure:apimanagement/logger:Logger",
  "fields": {
    "name": {
      "name": "name",
      "typeomitempty": "",
      "default": {
        "autonamed": true,
        "isFunc": true
      }
    }
  },
  "idFields": null
}
provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

resource "azurerm_application_insights" "example" {
  name                = "example-appinsights"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  application_type    = "web"
}

resource "azurerm_api_management" "example" {
  name                = "example-apim"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  publisher_name      = "My Company"
  publisher_email     = "company@mycompany.io"
  sku_name            = "Developer_1"
}

resource "azurerm_api_management_api" "example" {
  name                = "example-api"
  resource_group_name = azurerm_resource_group.example.name
  api_management_name = azurerm_api_management.example.name
  revision            = "1"
  display_name        = "Example API"
  path                = "example"
  protocols           = ["https"]

  import {
    content_format = "swagger-link-json"
    content_value  = "http://conferenceapi.azurewebsites.net/?format=json"
  }
}

resource "azurerm_api_management_logger" "example" {
  name                = "example-apimlogger"
  api_management_name = azurerm_api_management.example.name
  resource_group_name = azurerm_resource_group.example.name

  application_insights {
    instrumentation_key = azurerm_application_insights.example.instrumentation_key
  }
}

resource "azurerm_api_management_api_diagnostic" "example" {
  identifier               = "applicationinsights"
  resource_group_name      = azurerm_resource_group.example.name
  api_management_name      = azurerm_api_management.example.name
  api_name                 = azurerm_api_management_api.example.name
  api_management_logger_id = azurerm_api_management_logger.example.id

  sampling_percentage       = 5.0
  always_log_errors         = true
  log_client_ip             = true
  verbosity                 = "verbose"
  http_correlation_protocol = "W3C"

  frontend_request {
    body_bytes = 32
    headers_to_log = [
      "content-type",
      "accept",
      "origin",
    ]
  }

  frontend_response {
    body_bytes = 32
    headers_to_log = [
      "content-type",
      "content-length",
      "origin",
    ]
  }

  backend_request {
    body_bytes = 32
    headers_to_log = [
      "content-type",
      "accept",
      "origin",
    ]
  }

  backend_response {
    body_bytes = 32
    headers_to_log = [
      "content-type",
      "content-length",
      "origin",
    ]
  }
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Azure = Pulumi.Azure;

return await Deployment.RunAsync(() => 
{
    var example = new Azure.Core.ResourceGroup("example", new()
    {
        Name = "example-resources", // HERE
        Location = "West Europe",
    });

    var exampleInsights = new Azure.AppInsights.Insights("example", new()
    {
        Name = "example-appinsights", // HERE
        Location = example.Location,
        ResourceGroupName = example.Name,
        ApplicationType = "web",
    });

    var exampleService = new Azure.ApiManagement.Service("example", new()
    {
        Name = "example-apim", // HERE
        Location = example.Location,
        ResourceGroupName = example.Name,
        PublisherName = "My Company",
        PublisherEmail = "company@mycompany.io",
        SkuName = "Developer_1",
    });

    var exampleApi = new Azure.ApiManagement.Api("example", new()
    {
        Name = "example-api",
        ResourceGroupName = example.Name,
        ApiManagementName = exampleService.Name,
        Revision = "1",
        DisplayName = "Example API",
        Path = "example",
        Protocols = new[]
        {
            "https",
        },
        Import = new Azure.ApiManagement.Inputs.ApiImportArgs
        {
            ContentFormat = "swagger-link-json",
            ContentValue = "http://conferenceapi.azurewebsites.net/?format=json",
        },
    });

    var exampleLogger = new Azure.ApiManagement.Logger("example", new()
    {
        Name = "example-apimlogger",
        ApiManagementName = exampleService.Name,
        ResourceGroupName = example.Name,
        ApplicationInsights = new Azure.ApiManagement.Inputs.LoggerApplicationInsightsArgs
        {
            InstrumentationKey = exampleInsights.InstrumentationKey,
        },
    });

    var exampleApiDiagnostic = new Azure.ApiManagement.ApiDiagnostic("example", new()
    {
        Identifier = "applicationinsights",
        ResourceGroupName = example.Name,
        ApiManagementName = exampleService.Name,
        ApiName = exampleApi.Name,
        ApiManagementLoggerId = exampleLogger.Id,
        SamplingPercentage = 5,
        AlwaysLogErrors = true,
        LogClientIp = true,
        Verbosity = "verbose",
        HttpCorrelationProtocol = "W3C",
        FrontendRequest = new Azure.ApiManagement.Inputs.ApiDiagnosticFrontendRequestArgs
        {
            BodyBytes = 32,
            HeadersToLogs = new[]
            {
                "content-type",
                "accept",
                "origin",
            },
        },
        FrontendResponse = new Azure.ApiManagement.Inputs.ApiDiagnosticFrontendResponseArgs
        {
            BodyBytes = 32,
            HeadersToLogs = new[]
            {
                "content-type",
                "content-length",
                "origin",
            },
        },
        BackendRequest = new Azure.ApiManagement.Inputs.ApiDiagnosticBackendRequestArgs
        {
            BodyBytes = 32,
            HeadersToLogs = new[]
            {
                "content-type",
                "accept",
                "origin",
            },
        },
        BackendResponse = new Azure.ApiManagement.Inputs.ApiDiagnosticBackendResponseArgs
        {
            BodyBytes = 32,
            HeadersToLogs = new[]
            {
                "content-type",
                "content-length",
                "origin",
            },
        },
    });

});

Affected area/feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements or new features
Projects
None yet
Development

No branches or pull requests

2 participants