1. Packages
  2. Nsxt Provider
  3. API Docs
  4. getNsServices
nsxt 3.8.1 published on Wednesday, Apr 30, 2025 by vmware

nsxt.getNsServices

Explore with Pulumi AI

nsxt logo
nsxt 3.8.1 published on Wednesday, Apr 30, 2025 by vmware

    This data source builds a “name to uuid” map of the whole NS Services table. Such map can be referenced in configuration to obtain object uuids by display name at a cost of single roundtrip to NSX, which improves apply and refresh time at scale, compared to multiple instances of nsxt.getNsService data source.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as nsxt from "@pulumi/nsxt";
    
    const map = nsxt.getNsServices({});
    const s1 = new nsxt.FirewallSection("s1", {
        displayName: "section1",
        rules: [{
            displayName: "in_rule",
            action: "DROP",
            direction: "IN",
            services: [{
                targetType: "NSService",
                targetId: map.then(map => map.items?.service1),
            }],
        }],
        sectionType: "LAYER3",
    });
    
    import pulumi
    import pulumi_nsxt as nsxt
    
    map = nsxt.get_ns_services()
    s1 = nsxt.FirewallSection("s1",
        display_name="section1",
        rules=[{
            "display_name": "in_rule",
            "action": "DROP",
            "direction": "IN",
            "services": [{
                "target_type": "NSService",
                "target_id": map.items["service1"],
            }],
        }],
        section_type="LAYER3")
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-terraform-provider/sdks/go/nsxt/v3/nsxt"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_map, err := nsxt.GetNsServices(ctx, &nsxt.GetNsServicesArgs{}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = nsxt.NewFirewallSection(ctx, "s1", &nsxt.FirewallSectionArgs{
    			DisplayName: pulumi.String("section1"),
    			Rules: nsxt.FirewallSectionRuleArray{
    				&nsxt.FirewallSectionRuleArgs{
    					DisplayName: pulumi.String("in_rule"),
    					Action:      pulumi.String("DROP"),
    					Direction:   pulumi.String("IN"),
    					Services: nsxt.FirewallSectionRuleServiceArray{
    						&nsxt.FirewallSectionRuleServiceArgs{
    							TargetType: pulumi.String("NSService"),
    							TargetId:   pulumi.String(_map.Items.Service1),
    						},
    					},
    				},
    			},
    			SectionType: pulumi.String("LAYER3"),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Nsxt = Pulumi.Nsxt;
    
    return await Deployment.RunAsync(() => 
    {
        var map = Nsxt.GetNsServices.Invoke();
    
        var s1 = new Nsxt.FirewallSection("s1", new()
        {
            DisplayName = "section1",
            Rules = new[]
            {
                new Nsxt.Inputs.FirewallSectionRuleArgs
                {
                    DisplayName = "in_rule",
                    Action = "DROP",
                    Direction = "IN",
                    Services = new[]
                    {
                        new Nsxt.Inputs.FirewallSectionRuleServiceArgs
                        {
                            TargetType = "NSService",
                            TargetId = map.Apply(getNsServicesResult => getNsServicesResult.Items?.Service1),
                        },
                    },
                },
            },
            SectionType = "LAYER3",
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.nsxt.NsxtFunctions;
    import com.pulumi.nsxt.inputs.GetNsServicesArgs;
    import com.pulumi.nsxt.FirewallSection;
    import com.pulumi.nsxt.FirewallSectionArgs;
    import com.pulumi.nsxt.inputs.FirewallSectionRuleArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            final var map = NsxtFunctions.getNsServices();
    
            var s1 = new FirewallSection("s1", FirewallSectionArgs.builder()
                .displayName("section1")
                .rules(FirewallSectionRuleArgs.builder()
                    .displayName("in_rule")
                    .action("DROP")
                    .direction("IN")
                    .services(FirewallSectionRuleServiceArgs.builder()
                        .targetType("NSService")
                        .targetId(map.applyValue(getNsServicesResult -> getNsServicesResult.items().service1()))
                        .build())
                    .build())
                .sectionType("LAYER3")
                .build());
    
        }
    }
    
    resources:
      s1:
        type: nsxt:FirewallSection
        properties:
          displayName: section1
          rules:
            - displayName: in_rule
              action: DROP
              direction: IN
              services:
                - targetType: NSService
                  targetId: ${map.items.service1}
          sectionType: LAYER3
    variables:
      map:
        fn::invoke:
          function: nsxt:getNsServices
          arguments: {}
    

    Using getNsServices

    Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

    function getNsServices(args: GetNsServicesArgs, opts?: InvokeOptions): Promise<GetNsServicesResult>
    function getNsServicesOutput(args: GetNsServicesOutputArgs, opts?: InvokeOptions): Output<GetNsServicesResult>
    def get_ns_services(id: Optional[str] = None,
                        opts: Optional[InvokeOptions] = None) -> GetNsServicesResult
    def get_ns_services_output(id: Optional[pulumi.Input[str]] = None,
                        opts: Optional[InvokeOptions] = None) -> Output[GetNsServicesResult]
    func GetNsServices(ctx *Context, args *GetNsServicesArgs, opts ...InvokeOption) (*GetNsServicesResult, error)
    func GetNsServicesOutput(ctx *Context, args *GetNsServicesOutputArgs, opts ...InvokeOption) GetNsServicesResultOutput

    > Note: This function is named GetNsServices in the Go SDK.

    public static class GetNsServices 
    {
        public static Task<GetNsServicesResult> InvokeAsync(GetNsServicesArgs args, InvokeOptions? opts = null)
        public static Output<GetNsServicesResult> Invoke(GetNsServicesInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetNsServicesResult> getNsServices(GetNsServicesArgs args, InvokeOptions options)
    public static Output<GetNsServicesResult> getNsServices(GetNsServicesArgs args, InvokeOptions options)
    
    fn::invoke:
      function: nsxt:index/getNsServices:getNsServices
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Id string
    Id string
    id String
    id string
    id str
    id String

    getNsServices Result

    The following output properties are available:

    Id string
    Items Dictionary<string, string>
    Map of ns service uuids keyed by display name.
    Id string
    Items map[string]string
    Map of ns service uuids keyed by display name.
    id String
    items Map<String,String>
    Map of ns service uuids keyed by display name.
    id string
    items {[key: string]: string}
    Map of ns service uuids keyed by display name.
    id str
    items Mapping[str, str]
    Map of ns service uuids keyed by display name.
    id String
    items Map<String>
    Map of ns service uuids keyed by display name.

    Package Details

    Repository
    nsxt vmware/terraform-provider-nsxt
    License
    Notes
    This Pulumi package is based on the nsxt Terraform Provider.
    nsxt logo
    nsxt 3.8.1 published on Wednesday, Apr 30, 2025 by vmware