1. Packages
  2. Ibm Provider
  3. API Docs
  4. getSecurityGroup
ibm 1.77.1 published on Monday, Apr 14, 2025 by ibm-cloud

ibm.getSecurityGroup

Explore with Pulumi AI

ibm 1.77.1 published on Monday, Apr 14, 2025 by ibm-cloud

Retrieve information of an existing security group as a read-only data source. For more information, about IBM Cloud security group, see managing security groups.

Example Usage

The following example shows how you can use this data source to reference the security group IDs in the ibm.ComputeVmInstance resource because the numeric IDs are often unknown.

import * as pulumi from "@pulumi/pulumi";
import * as ibm from "@pulumi/ibm";

const allowSsh = ibm.getSecurityGroup({
    name: "allow_ssh",
});
const vm1 = new ibm.ComputeVmInstance("vm1", {privateSecurityGroupIds: [allowSsh.then(allowSsh => allowSsh.id)]});
Copy
import pulumi
import pulumi_ibm as ibm

allow_ssh = ibm.get_security_group(name="allow_ssh")
vm1 = ibm.ComputeVmInstance("vm1", private_security_group_ids=[allow_ssh.id])
Copy
package main

import (
	"github.com/pulumi/pulumi-terraform-provider/sdks/go/ibm/ibm"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		allowSsh, err := ibm.LookupSecurityGroup(ctx, &ibm.LookupSecurityGroupArgs{
			Name: "allow_ssh",
		}, nil)
		if err != nil {
			return err
		}
		_, err = ibm.NewComputeVmInstance(ctx, "vm1", &ibm.ComputeVmInstanceArgs{
			PrivateSecurityGroupIds: pulumi.Float64Array{
				pulumi.String(allowSsh.Id),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Ibm = Pulumi.Ibm;

return await Deployment.RunAsync(() => 
{
    var allowSsh = Ibm.GetSecurityGroup.Invoke(new()
    {
        Name = "allow_ssh",
    });

    var vm1 = new Ibm.ComputeVmInstance("vm1", new()
    {
        PrivateSecurityGroupIds = new[]
        {
            allowSsh.Apply(getSecurityGroupResult => getSecurityGroupResult.Id),
        },
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.ibm.IbmFunctions;
import com.pulumi.ibm.inputs.GetSecurityGroupArgs;
import com.pulumi.ibm.ComputeVmInstance;
import com.pulumi.ibm.ComputeVmInstanceArgs;
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 allowSsh = IbmFunctions.getSecurityGroup(GetSecurityGroupArgs.builder()
            .name("allow_ssh")
            .build());

        var vm1 = new ComputeVmInstance("vm1", ComputeVmInstanceArgs.builder()
            .privateSecurityGroupIds(allowSsh.applyValue(getSecurityGroupResult -> getSecurityGroupResult.id()))
            .build());

    }
}
Copy
resources:
  vm1:
    type: ibm:ComputeVmInstance
    properties:
      # TF-UPGRADE-TODO: In Terraform v0.10 and earlier, it was sometimes necessary to
      #   # force an interpolation expression to be interpreted as a list by wrapping it
      #   # in an extra set of list brackets. That form was supported for compatibility in
      #   # v0.11, but is no longer supported in Terraform v0.12.
      #   #
      #   # If the expression in the following list itself returns a list, remove the
      #   # brackets to avoid interpretation as a list of lists. If the expression
      #   # returns a single list item then leave it as-is and remove this TODO comment.
      privateSecurityGroupIds:
        - ${allowSsh.id}
variables:
  allowSsh:
    fn::invoke:
      function: ibm:getSecurityGroup
      arguments:
        name: allow_ssh
Copy

Using getSecurityGroup

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 getSecurityGroup(args: GetSecurityGroupArgs, opts?: InvokeOptions): Promise<GetSecurityGroupResult>
function getSecurityGroupOutput(args: GetSecurityGroupOutputArgs, opts?: InvokeOptions): Output<GetSecurityGroupResult>
Copy
def get_security_group(description: Optional[str] = None,
                       id: Optional[str] = None,
                       most_recent: Optional[bool] = None,
                       name: Optional[str] = None,
                       opts: Optional[InvokeOptions] = None) -> GetSecurityGroupResult
def get_security_group_output(description: Optional[pulumi.Input[str]] = None,
                       id: Optional[pulumi.Input[str]] = None,
                       most_recent: Optional[pulumi.Input[bool]] = None,
                       name: Optional[pulumi.Input[str]] = None,
                       opts: Optional[InvokeOptions] = None) -> Output[GetSecurityGroupResult]
Copy
func LookupSecurityGroup(ctx *Context, args *LookupSecurityGroupArgs, opts ...InvokeOption) (*LookupSecurityGroupResult, error)
func LookupSecurityGroupOutput(ctx *Context, args *LookupSecurityGroupOutputArgs, opts ...InvokeOption) LookupSecurityGroupResultOutput
Copy

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

public static class GetSecurityGroup 
{
    public static Task<GetSecurityGroupResult> InvokeAsync(GetSecurityGroupArgs args, InvokeOptions? opts = null)
    public static Output<GetSecurityGroupResult> Invoke(GetSecurityGroupInvokeArgs args, InvokeOptions? opts = null)
}
Copy
public static CompletableFuture<GetSecurityGroupResult> getSecurityGroup(GetSecurityGroupArgs args, InvokeOptions options)
public static Output<GetSecurityGroupResult> getSecurityGroup(GetSecurityGroupArgs args, InvokeOptions options)
Copy
fn::invoke:
  function: ibm:index/getSecurityGroup:getSecurityGroup
  arguments:
    # arguments dictionary
Copy

The following arguments are supported:

Name This property is required. string
The name of the security group, as defined in IBM Cloud Classic Infrastructure.
Description string
The description of the security group, as defined in IBM Cloud Classic Infrastructure.
Id string
(String) The unique identifier of the security group.
MostRecent bool
Name This property is required. string
The name of the security group, as defined in IBM Cloud Classic Infrastructure.
Description string
The description of the security group, as defined in IBM Cloud Classic Infrastructure.
Id string
(String) The unique identifier of the security group.
MostRecent bool
name This property is required. String
The name of the security group, as defined in IBM Cloud Classic Infrastructure.
description String
The description of the security group, as defined in IBM Cloud Classic Infrastructure.
id String
(String) The unique identifier of the security group.
mostRecent Boolean
name This property is required. string
The name of the security group, as defined in IBM Cloud Classic Infrastructure.
description string
The description of the security group, as defined in IBM Cloud Classic Infrastructure.
id string
(String) The unique identifier of the security group.
mostRecent boolean
name This property is required. str
The name of the security group, as defined in IBM Cloud Classic Infrastructure.
description str
The description of the security group, as defined in IBM Cloud Classic Infrastructure.
id str
(String) The unique identifier of the security group.
most_recent bool
name This property is required. String
The name of the security group, as defined in IBM Cloud Classic Infrastructure.
description String
The description of the security group, as defined in IBM Cloud Classic Infrastructure.
id String
(String) The unique identifier of the security group.
mostRecent Boolean

getSecurityGroup Result

The following output properties are available:

Description string
(String) The description of the security group.
Id string
(String) The unique identifier of the security group.
Name string
MostRecent bool
Description string
(String) The description of the security group.
Id string
(String) The unique identifier of the security group.
Name string
MostRecent bool
description String
(String) The description of the security group.
id String
(String) The unique identifier of the security group.
name String
mostRecent Boolean
description string
(String) The description of the security group.
id string
(String) The unique identifier of the security group.
name string
mostRecent boolean
description str
(String) The description of the security group.
id str
(String) The unique identifier of the security group.
name str
most_recent bool
description String
(String) The description of the security group.
id String
(String) The unique identifier of the security group.
name String
mostRecent Boolean

Package Details

Repository
ibm ibm-cloud/terraform-provider-ibm
License
Notes
This Pulumi package is based on the ibm Terraform Provider.
ibm 1.77.1 published on Monday, Apr 14, 2025 by ibm-cloud