Skip to content

create_workload_identity_template

create_workload_identity_template(
    *,
    config_overrides: Optional[IAMClientConfig] = None,
    name: Optional[WorkloadIdentityTemplateNameType] = None,
    description: Optional[WorkloadIdentityDescriptionType] = None,
    resource_scope: Optional[WorkloadIdentityResourceScopeType] = None,
    workload_identity_provider_arn: Optional[arnType] = None,
    path_prefix: Optional[WorkloadIdentityPathPrefixType] = None,
    path_pattern: Optional[WorkloadIdentityTemplatePathPatternType] = None,
    attestation_policy: Optional[policyDocumentType] = None,
    tags: Optional[tagListType] = None,
    template_definition: Optional[WorkloadIdentityTemplateDefinitionType] = None,
) -> CreateWorkloadIdentityTemplateResponse

Creates a workload identity template under a workload identity provider.

The operation accepts two mutually exclusive modes, and the member you supply decides which one you are in. TemplateDefinition puts the request in template definition mode, and PathPattern puts it in direct authoring mode.

Use template definition mode when a service-owned definition already covers the workload you are onboarding. IAM then renders the pattern and the attestation policy for you, so there is less to get wrong. Use direct authoring mode when no definition covers your case, or when you need a pattern or an attestation policy that the available definitions do not offer.

  • Template definition mode – You name a service-owned definition through TemplateDefinition and supply only the values that definition leaves open. WorkloadIdentityTemplateDefinitionType carries which values a given definition leaves open and the name it gives each one. IAM renders PathPattern and AttestationPolicy from the definition, so you author neither. In this mode, Tags is the only other request parameter you can supply.

  • Direct authoring mode – You must supply Name, WorkloadIdentityProviderArn and PathPattern yourself, and you can supply Description, PathPrefix, AttestationPolicy and Tags.

Because the two modes make different members mandatory, no member of this request is unconditionally required, and every parameter below therefore reads Required: No. The per-mode rules are what govern. TemplateDefinition is required in template definition mode and forbidden in direct authoring mode. Name, WorkloadIdentityProviderArn and PathPattern are required in direct authoring mode and forbidden in template definition mode, where IAM renders all three from the definition.

AttestationPolicy is optional on this operation. A policy supplied here is equivalent to one supplied later by PutWorkloadIdentityTemplateAttestationPolicy, and a template created without one admits nothing until a policy is set.

Parameters:

  • name (Optional[WorkloadIdentityTemplateNameType], default: None ) –

    The name of the template. It is the leaf of the template's own resource ARN and it does not appear in any rendered identifier.

    Required in direct authoring mode, and forbidden in template definition mode.

  • description (Optional[WorkloadIdentityDescriptionType], default: None ) –

    A description of the template. If you omit it, the template carries no description and responses omit the Description element.

    Forbidden in template definition mode.

  • resource_scope (Optional[WorkloadIdentityResourceScopeType], default: None ) –

    The scope the template is created at. An ORGANIZATION-scoped template belongs to your organization. If you do not include this parameter, it defaults to ACCOUNT.

    An ORGANIZATION-scoped template must reference an organization-scoped provider. An ACCOUNT-scoped template can reference an account-scoped provider in your account or an organization-scoped provider in your organization.

    Forbidden in template definition mode.

  • workload_identity_provider_arn (Optional[arnType], default: None ) –

    The Amazon Resource Name (ARN) of the workload identity provider to create the template under.

    Required in direct authoring mode, and forbidden in template definition mode, where the service renders it from the definition.

  • path_prefix (Optional[WorkloadIdentityPathPrefixType], default: None ) –

    The namespace between the provider's naming root and the rendered pattern. Segments only, with no leading slash, no trailing slash and no empty segment.

    Forbidden in template definition mode.

  • path_pattern (Optional[WorkloadIdentityTemplatePathPatternType], default: None ) –

    The pattern that workload identifiers are rendered from. For the pattern grammar, and for the checks the regular expression cannot express, see WorkloadIdentityTemplatePathPatternType.

    Required in direct authoring mode, and forbidden in template definition mode, where the service renders it from the definition.

  • attestation_policy (Optional[policyDocumentType], default: None ) –

    The attestation policy that decides which workloads can be attested through the template. A policy supplied here is equivalent to one supplied later by PutWorkloadIdentityTemplateAttestationPolicy.

    Forbidden in template definition mode, where the service renders the policy from the definition.

  • tags (Optional[tagListType], default: None ) –

    A list of tags that you want to attach to the new template. Each tag consists of a key name and an associated value. Tag keys are case sensitive, and two tag keys that differ only in case are rejected with InvalidInputException. For more information about tagging, see Tagging IAM resources in the IAM User Guide.

    Tags is accepted in both modes. A template definition never carries tags of its own.

    If any one of the tags is invalid or if you exceed the allowed maximum number of tags, then the entire request fails and the resource is not created.

  • template_definition (Optional[WorkloadIdentityTemplateDefinitionType], default: None ) –

    The service-owned definition to render the template from, carrying only the values that definition leaves open. For the values a definition leaves open and the name of each, see WorkloadIdentityTemplateDefinitionType.

    Supplying this parameter selects template definition mode. It is forbidden in direct authoring mode.

Raises:

  • ConcurrentModificationException –

    The request was rejected because multiple requests to change this object were submitted simultaneously. Wait a few minutes and submit your request again.

  • EntityAlreadyExistsException –

    The request was rejected because it attempted to create a resource that already exists.

  • InvalidInputException –

    The request was rejected because an invalid or out-of-range value was supplied for an input parameter.

  • LimitExceededException –

    The request was rejected because it attempted to create resources beyond the current Amazon Web Services account limits. The error message describes the limit exceeded.

  • MalformedPolicyDocumentException –

    The request was rejected because the policy document was malformed. The error message describes the specific error.

  • NoSuchEntityException –

    The request was rejected because it referenced a resource entity that does not exist. The error message describes the resource.

  • ServiceFailureException –

    The request processing has failed because of an unknown error, exception or failure.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_iam/_services/iam.py
def create_workload_identity_template(
    self,
    *,
    config_overrides: Optional[IAMClientConfig] = None,
    name: Optional[
        "capo_iam.types.workload_identity_template_name_type.WorkloadIdentityTemplateNameType"
    ] = None,
    description: Optional[
        "capo_iam.types.workload_identity_description_type.WorkloadIdentityDescriptionType"
    ] = None,
    resource_scope: Optional[
        "capo_iam.types.workload_identity_resource_scope_type.WorkloadIdentityResourceScopeType"
    ] = None,
    workload_identity_provider_arn: Optional[
        "capo_iam.types.arn_type.arnType"
    ] = None,
    path_prefix: Optional[
        "capo_iam.types.workload_identity_path_prefix_type.WorkloadIdentityPathPrefixType"
    ] = None,
    path_pattern: Optional[
        "capo_iam.types.workload_identity_template_path_pattern_type.WorkloadIdentityTemplatePathPatternType"
    ] = None,
    attestation_policy: Optional[
        "capo_iam.types.policy_document_type.policyDocumentType"
    ] = None,
    tags: Optional["capo_iam.types.tag_list_type.tagListType"] = None,
    template_definition: Optional[
        "capo_iam.types.workload_identity_template_definition_type.WorkloadIdentityTemplateDefinitionType"
    ] = None,
) -> "capo_iam.types.create_workload_identity_template_response.CreateWorkloadIdentityTemplateResponse":
    """<p>Creates a workload identity template under a workload identity provider.</p> <p>The operation accepts two mutually exclusive modes, and the member you supply decides which one you are in. <code>TemplateDefinition</code> puts the request in template definition mode, and <code>PathPattern</code> puts it in direct authoring mode.</p> <p>Use template definition mode when a service-owned definition already covers the workload you are onboarding. IAM then renders the pattern and the attestation policy for you, so there is less to get wrong. Use direct authoring mode when no definition covers your case, or when you need a pattern or an attestation policy that the available definitions do not offer.</p> <ul> <li> <p> <b>Template definition mode</b> – You name a service-owned definition through <code>TemplateDefinition</code> and supply only the values that definition leaves open. <a href="https://docs.aws.amazon.com/IAM/latest/APIReference/API_WorkloadIdentityTemplateDefinitionType.html">WorkloadIdentityTemplateDefinitionType</a> carries which values a given definition leaves open and the name it gives each one. IAM renders <code>PathPattern</code> and <code>AttestationPolicy</code> from the definition, so you author neither. In this mode, <code>Tags</code> is the only other request parameter you can supply.</p> </li> <li> <p> <b>Direct authoring mode</b> – You must supply <code>Name</code>, <code>WorkloadIdentityProviderArn</code> and <code>PathPattern</code> yourself, and you can supply <code>Description</code>, <code>PathPrefix</code>, <code>AttestationPolicy</code> and <code>Tags</code>.</p> </li> </ul> <p>Because the two modes make different members mandatory, no member of this request is unconditionally required, and every parameter below therefore reads <code>Required: No</code>. The per-mode rules are what govern. <code>TemplateDefinition</code> is required in template definition mode and forbidden in direct authoring mode. <code>Name</code>, <code>WorkloadIdentityProviderArn</code> and <code>PathPattern</code> are required in direct authoring mode and forbidden in template definition mode, where IAM renders all three from the definition.</p> <p> <code>AttestationPolicy</code> is optional on this operation. A policy supplied here is equivalent to one supplied later by <a href="https://docs.aws.amazon.com/IAM/latest/APIReference/API_PutWorkloadIdentityTemplateAttestationPolicy.html">PutWorkloadIdentityTemplateAttestationPolicy</a>, and a template created without one admits nothing until a policy is set.</p>

    Args:
        name: <p>The name of the template. It is the leaf of the template's own resource ARN and it does not appear in any rendered identifier.</p> <p>Required in direct authoring mode, and forbidden in template definition mode.</p>
        description: <p>A description of the template. If you omit it, the template carries no description and responses omit the <code>Description</code> element.</p> <p>Forbidden in template definition mode.</p>
        resource_scope: <p>The scope the template is created at. An <code>ORGANIZATION</code>-scoped template belongs to your organization. If you do not include this parameter, it defaults to <code>ACCOUNT</code>.</p> <p>An <code>ORGANIZATION</code>-scoped template must reference an organization-scoped provider. An <code>ACCOUNT</code>-scoped template can reference an account-scoped provider in your account or an organization-scoped provider in your organization.</p> <p>Forbidden in template definition mode.</p>
        workload_identity_provider_arn: <p>The Amazon Resource Name (ARN) of the workload identity provider to create the template under.</p> <p>Required in direct authoring mode, and forbidden in template definition mode, where the service renders it from the definition.</p>
        path_prefix: <p>The namespace between the provider's naming root and the rendered pattern. Segments only, with no leading slash, no trailing slash and no empty segment.</p> <p>Forbidden in template definition mode.</p>
        path_pattern: <p>The pattern that workload identifiers are rendered from. For the pattern grammar, and for the checks the regular expression cannot express, see <a href="https://docs.aws.amazon.com/IAM/latest/APIReference/API_WorkloadIdentityTemplatePathPatternType.html">WorkloadIdentityTemplatePathPatternType</a>.</p> <p>Required in direct authoring mode, and forbidden in template definition mode, where the service renders it from the definition.</p>
        attestation_policy: <p>The attestation policy that decides which workloads can be attested through the template. A policy supplied here is equivalent to one supplied later by <a href="https://docs.aws.amazon.com/IAM/latest/APIReference/API_PutWorkloadIdentityTemplateAttestationPolicy.html">PutWorkloadIdentityTemplateAttestationPolicy</a>.</p> <p>Forbidden in template definition mode, where the service renders the policy from the definition.</p>
        tags: <p>A list of tags that you want to attach to the new template. Each tag consists of a key name and an associated value. Tag keys are case sensitive, and two tag keys that differ only in case are rejected with <code>InvalidInputException</code>. For more information about tagging, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_tags.html">Tagging IAM resources</a> in the <i>IAM User Guide</i>.</p> <p> <code>Tags</code> is accepted in both modes. A template definition never carries tags of its own.</p> <note> <p>If any one of the tags is invalid or if you exceed the allowed maximum number of tags, then the entire request fails and the resource is not created.</p> </note>
        template_definition: <p>The service-owned definition to render the template from, carrying only the values that definition leaves open. For the values a definition leaves open and the name of each, see <a href="https://docs.aws.amazon.com/IAM/latest/APIReference/API_WorkloadIdentityTemplateDefinitionType.html">WorkloadIdentityTemplateDefinitionType</a>.</p> <p>Supplying this parameter selects template definition mode. It is forbidden in direct authoring mode.</p>

    Raises:
        capo_iam.errors.concurrent_modification_exception.ConcurrentModificationException: <p>The request was rejected because multiple requests to change this object were submitted simultaneously. Wait a few minutes and submit your request again.</p>
        capo_iam.errors.entity_already_exists_exception.EntityAlreadyExistsException: <p>The request was rejected because it attempted to create a resource that already exists.</p>
        capo_iam.errors.invalid_input_exception.InvalidInputException: <p>The request was rejected because an invalid or out-of-range value was supplied for an input parameter.</p>
        capo_iam.errors.limit_exceeded_exception.LimitExceededException: <p>The request was rejected because it attempted to create resources beyond the current Amazon Web Services account limits. The error message describes the limit exceeded.</p>
        capo_iam.errors.malformed_policy_document_exception.MalformedPolicyDocumentException: <p>The request was rejected because the policy document was malformed. The error message describes the specific error.</p>
        capo_iam.errors.no_such_entity_exception.NoSuchEntityException: <p>The request was rejected because it referenced a resource entity that does not exist. The error message describes the resource.</p>
        capo_iam.errors.service_failure_exception.ServiceFailureException: <p>The request processing has failed because of an unknown error, exception or failure.</p>
        capo_iam.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_iam.types.create_workload_identity_template_request.CreateWorkloadIdentityTemplateRequest]",
    ) -> OperationResponse[
        "capo_iam.types.create_workload_identity_template_response.CreateWorkloadIdentityTemplateResponse"
    ]:
        import capo_iam._operations.aws_identity_management_v20100508.create_workload_identity_template

        output, http_response = (
            capo_iam._operations.aws_identity_management_v20100508.create_workload_identity_template.create_workload_identity_template(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateWorkloadIdentityTemplate")
    )
    input_: capo_iam.types.create_workload_identity_template_request.CreateWorkloadIdentityTemplateRequest = {}
    if name is not None:
        input_["name"] = name
    if description is not None:
        input_["description"] = description
    if resource_scope is not None:
        input_["resource_scope"] = resource_scope
    if workload_identity_provider_arn is not None:
        input_["workload_identity_provider_arn"] = workload_identity_provider_arn
    if path_prefix is not None:
        input_["path_prefix"] = path_prefix
    if path_pattern is not None:
        input_["path_pattern"] = path_pattern
    if attestation_policy is not None:
        input_["attestation_policy"] = attestation_policy
    if tags is not None:
        input_["tags"] = tags
    if template_definition is not None:
        input_["template_definition"] = template_definition

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output