ModelPackageGroupPolicy class

Provides a SageMaker AI Model Package Group Policy resource.

Example Usage

Basic usage

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as std from "@pulumi/std";

const current = aws.getCallerIdentity({});
const exampleModelPackageGroup = new aws.sagemaker.ModelPackageGroup("example", {modelPackageGroupName: "example"});
const example = aws.iam.getPolicyDocumentOutput({
    statements: [{
        principals: [{
            identifiers: [current.then(current => current.accountId)],
            type: "AWS",
        }],
        sid: "AddPermModelPackageGroup",
        actions: [
            "sagemaker:DescribeModelPackage",
            "sagemaker:ListModelPackages",
        ],
        resources: [exampleModelPackageGroup.arn],
    }],
});
const exampleModelPackageGroupPolicy = new aws.sagemaker.ModelPackageGroupPolicy("example", {
    modelPackageGroupName: exampleModelPackageGroup.modelPackageGroupName,
    resourcePolicy: pulumi.jsonStringify(std.jsondecodeOutput({
        input: example.json,
    }).result),
});
import pulumi
import json
import pulumi_aws as aws
import pulumi_std as std

current = aws.get_caller_identity()
example_model_package_group = aws.sagemaker.ModelPackageGroup("example", model_package_group_name="example")
example = aws.iam.get_policy_document_output(statements=[{
    "principals": [{
        "identifiers": [current.account_id],
        "type": "AWS",
    }],
    "sid": "AddPermModelPackageGroup",
    "actions": [
        "sagemaker:DescribeModelPackage",
        "sagemaker:ListModelPackages",
    ],
    "resources": [example_model_package_group.arn],
}])
example_model_package_group_policy = aws.sagemaker.ModelPackageGroupPolicy("example",
    model_package_group_name=example_model_package_group.model_package_group_name,
    resource_policy=pulumi.Output.json_dumps(std.jsondecode_output(input=example.json).result))
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;
using Std = Pulumi.Std;

return await Deployment.RunAsync(() =>
{
    var current = Aws.GetCallerIdentity.Invoke();

    var exampleModelPackageGroup = new Aws.Sagemaker.ModelPackageGroup("example", new()
    {
        ModelPackageGroupName = "example",
    });

    var example = Aws.Iam.GetPolicyDocument.Invoke(new()
    {
        Statements = new[]
        {
            new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
            {
                Principals = new[]
                {
                    new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
                    {
                        Identifiers = new[]
                        {
                            current.Apply(getCallerIdentityResult => getCallerIdentityResult.AccountId),
                        },
                        Type = "AWS",
                    },
                },
                Sid = "AddPermModelPackageGroup",
                Actions = new[]
                {
                    "sagemaker:DescribeModelPackage",
                    "sagemaker:ListModelPackages",
                },
                Resources = new[]
                {
                    exampleModelPackageGroup.Arn,
                },
            },
        },
    });

    var exampleModelPackageGroupPolicy = new Aws.Sagemaker.ModelPackageGroupPolicy("example", new()
    {
        ModelPackageGroupName = exampleModelPackageGroup.ModelPackageGroupName,
        ResourcePolicy = Output.JsonSerialize(Output.Create(Std.Jsondecode.Invoke(new()
        {
            Input = example.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
        }).Apply(invoke => invoke.Result))),
    });

});
package main

import (
	"encoding/json"

	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws"
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/iam"
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/sagemaker"
	"github.com/pulumi/pulumi-std/sdk/go/std"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		current, err := aws.GetCallerIdentity(ctx, &aws.GetCallerIdentityArgs{}, nil)
		if err != nil {
			return err
		}
		exampleModelPackageGroup, err := sagemaker.NewModelPackageGroup(ctx, "example", &sagemaker.ModelPackageGroupArgs{
			ModelPackageGroupName: pulumi.String("example"),
		})
		if err != nil {
			return err
		}
		example := iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{
			Statements: iam.GetPolicyDocumentStatementArray{
				&iam.GetPolicyDocumentStatementArgs{
					Principals: iam.GetPolicyDocumentStatementPrincipalArray{
						&iam.GetPolicyDocumentStatementPrincipalArgs{
							Identifiers: pulumi.StringArray{
								pulumi.String(current.AccountId),
							},
							Type: pulumi.String("AWS"),
						},
					},
					Sid: pulumi.String("AddPermModelPackageGroup"),
					Actions: pulumi.StringArray{
						pulumi.String("sagemaker:DescribeModelPackage"),
						pulumi.String("sagemaker:ListModelPackages"),
					},
					Resources: pulumi.StringArray{
						exampleModelPackageGroup.Arn,
					},
				},
			},
		}, nil)
		_, err = sagemaker.NewModelPackageGroupPolicy(ctx, "example", &sagemaker.ModelPackageGroupPolicyArgs{
			ModelPackageGroupName: exampleModelPackageGroup.ModelPackageGroupName,
			ResourcePolicy: std.JsondecodeOutput(ctx, std.JsondecodeOutputArgs{
				Input: example.Json(),
			}, nil).ApplyT(func(invoke std.JsondecodeResult) (pulumi.String, error) {
				var _zero pulumi.String
				tmpJSON0, err := json.Marshal(invoke.Result)
				if err != nil {
					return _zero, err
				}
				json0 := string(tmpJSON0)
				return pulumi.String(json0), nil
			}).(pulumi.StringOutput),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
    std = {
      source = "pulumi/std"
    }
  }
}

data "aws_getcalleridentity" "current" {
}
data "aws_iam_getpolicydocument" "example" {
  statements {
    principals {
      identifiers = [data.aws_getcalleridentity.current.account_id]
      type        = "AWS"
    }
    sid       = "AddPermModelPackageGroup"
    actions   = ["sagemaker:DescribeModelPackage", "sagemaker:ListModelPackages"]
    resources = [aws_sagemaker_modelpackagegroup.example.arn]
  }
}

resource "aws_sagemaker_modelpackagegroup" "example" {
  model_package_group_name = "example"
}
resource "aws_sagemaker_modelpackagegrouppolicy" "example" {
  model_package_group_name = aws_sagemaker_modelpackagegroup.example.model_package_group_name
  resource_policy          = jsonencode(jsondecode(data.aws_iam_getpolicydocument.example.json))
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.AwsFunctions;
import com.pulumi.aws.inputs.GetCallerIdentityArgs;
import com.pulumi.aws.sagemaker.ModelPackageGroup;
import com.pulumi.aws.sagemaker.ModelPackageGroupArgs;
import com.pulumi.aws.iam.IamFunctions;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementArgs;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementPrincipalArgs;
import com.pulumi.aws.sagemaker.ModelPackageGroupPolicy;
import com.pulumi.aws.sagemaker.ModelPackageGroupPolicyArgs;
import com.pulumi.std.StdFunctions;
import com.pulumi.std.inputs.JsondecodeArgs;
import static com.pulumi.codegen.internal.Serialization.*;
import java.util.ArrayList;
import java.util.Arrays;
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 current = AwsFunctions.getCallerIdentity(GetCallerIdentityArgs.builder()
            .build());

        var exampleModelPackageGroup = new ModelPackageGroup("exampleModelPackageGroup", ModelPackageGroupArgs.builder()
            .modelPackageGroupName("example")
            .build());

        final var example = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
            .statements(GetPolicyDocumentStatementArgs.builder()
                .principals(GetPolicyDocumentStatementPrincipalArgs.builder()
                    .identifiers(current.accountId())
                    .type("AWS")
                    .build())
                .sid("AddPermModelPackageGroup")
                .actions(
                    "sagemaker:DescribeModelPackage",
                    "sagemaker:ListModelPackages")
                .resources(exampleModelPackageGroup.arn())
                .build())
            .build());

        var exampleModelPackageGroupPolicy = new ModelPackageGroupPolicy("exampleModelPackageGroupPolicy", ModelPackageGroupPolicyArgs.builder()
            .modelPackageGroupName(exampleModelPackageGroup.modelPackageGroupName())
            .resourcePolicy(StdFunctions.jsondecode(JsondecodeArgs.builder()
                .input(example.applyValue(_example -> _example.json()))
                .build()).applyValue(_invoke -> serializeJson(
                _invoke.result())))
            .build());

    }
}
resources:
  exampleModelPackageGroup:
    type: aws:sagemaker:ModelPackageGroup
    name: example
    properties:
      modelPackageGroupName: example
  exampleModelPackageGroupPolicy:
    type: aws:sagemaker:ModelPackageGroupPolicy
    name: example
    properties:
      modelPackageGroupName: ${exampleModelPackageGroup.modelPackageGroupName}
      resourcePolicy:
        fn::toJSON:
          fn::invoke:
            function: std:jsondecode
            arguments:
              input: ${example.json}
            return: result
variables:
  current:
    fn::invoke:
      function: aws:getCallerIdentity
      arguments: {}
  example:
    fn::invoke:
      function: aws:iam:getPolicyDocument
      arguments:
        statements:
          - principals:
              - identifiers:
                  - ${current.accountId}
                type: AWS
            sid: AddPermModelPackageGroup
            actions:
              - sagemaker:DescribeModelPackage
              - sagemaker:ListModelPackages
            resources:
              - ${exampleModelPackageGroup.arn}

Import

Using pulumi import, import SageMaker AI Model Package Groups using the name. For example:

$ pulumi import aws:sagemaker/modelPackageGroupPolicy:ModelPackageGroupPolicy example example

Constructors

ModelPackageGroupPolicy(String name, {ModelPackageGroupPolicyArgs? args, CustomResourceOptions? options})
Creates a new ModelPackageGroupPolicy. name The Pulumi resource name. args Arguments used to configure this ModelPackageGroupPolicy. The set of arguments for ModelPackageGroupPolicy. options Resource options controlling this resource's behavior.
ModelPackageGroupPolicy.reference(String urn)
Creates a typed reference to an existing ModelPackageGroupPolicy resource.

Properties

childResources Set<Resource>
finalinherited
completionSources Map<String, IOutputCompletionSource>
latefinalinherited
hashCode int
The hash code for this object.
no setterinherited
id ↔ Output<String>
getter/setter pairinherited
isCustom bool
Returns whether this resource is provider-managed.
no setterinherited
isProtected bool
Returns whether this resource is protected from deletion.
no setterinherited
isRemote bool
Whether this resource is registered as remote.
no setterinherited
isResourceReference bool
Whether this instance represents a resource value returned over RPC.
finalinherited
modelPackageGroupName ↔ Output<String>
The name of the model package group.
latefinal
region ↔ Output<String>
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
resourcePolicy ↔ Output<String>
latefinal
resourceTransforms List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
transformations List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
urn ↔ Output<String>
latefinalinherited

Methods

failId(Object error) → void
Completes this resource ID with an error when registration fails.
inherited
failOutputs(Object error) → void
Completes all output properties with error.
inherited
failUrn(Object error) → void
Completes this resource URN with an error when registration fails.
inherited
getProvider(String moduleMember) → ProviderResource?
Returns provider for moduleMember's package, if configured.
inherited
getResourceName() String
Returns this resource's logical name.
inherited
getResourceType() String
Returns this resource's Pulumi type token.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerOutput<T>(String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output<T>
Registers a dynamic output property for this resource.
inherited
resolveId(String? value, {required bool isKnown}) → void
Resolves the provider-assigned ID for this resource.
inherited
resolveOutputs(Struct outputs) → void
Resolves all output properties from a monitor response payload.
inherited
resolveUrn(String value) → void
Resolves this resource's URN once assigned by the engine.
inherited
serializeProperties(Map<String, dynamic> properties) Future<Struct>
Serializes resource properties for RPC transmission.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

get(String name, Input<String> id, {ModelPackageGroupPolicyState? state, CustomResourceOptions? options}) ModelPackageGroupPolicy
Gets an existing ModelPackageGroupPolicy resource's state with the given name and id.