All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pulumi.aws.ec2.kotlin.NetworkAclRule.kt Maven / Gradle / Ivy

@file:Suppress("NAME_SHADOWING", "DEPRECATION")

package com.pulumi.aws.ec2.kotlin

import com.pulumi.core.Output
import com.pulumi.kotlin.KotlinCustomResource
import com.pulumi.kotlin.PulumiTagMarker
import com.pulumi.kotlin.ResourceMapper
import com.pulumi.kotlin.options.CustomResourceOptions
import com.pulumi.kotlin.options.CustomResourceOptionsBuilder
import com.pulumi.resources.Resource
import kotlin.Boolean
import kotlin.Int
import kotlin.String
import kotlin.Suppress
import kotlin.Unit

/**
 * Builder for [NetworkAclRule].
 */
@PulumiTagMarker
public class NetworkAclRuleResourceBuilder internal constructor() {
    public var name: String? = null

    public var args: NetworkAclRuleArgs = NetworkAclRuleArgs()

    public var opts: CustomResourceOptions = CustomResourceOptions()

    /**
     * @param name The _unique_ name of the resulting resource.
     */
    public fun name(`value`: String) {
        this.name = value
    }

    /**
     * @param block The arguments to use to populate this resource's properties.
     */
    public suspend fun args(block: suspend NetworkAclRuleArgsBuilder.() -> Unit) {
        val builder = NetworkAclRuleArgsBuilder()
        block(builder)
        this.args = builder.build()
    }

    /**
     * @param block A bag of options that control this resource's behavior.
     */
    public suspend fun opts(block: suspend CustomResourceOptionsBuilder.() -> Unit) {
        this.opts = com.pulumi.kotlin.options.CustomResourceOptions.opts(block)
    }

    internal fun build(): NetworkAclRule {
        val builtJavaResource = com.pulumi.aws.ec2.NetworkAclRule(
            this.name,
            this.args.toJava(),
            this.opts.toJava(),
        )
        return NetworkAclRule(builtJavaResource)
    }
}

/**
 * Creates an entry (a rule) in a network ACL with the specified rule number.
 * > **NOTE on Network ACLs and Network ACL Rules:** This provider currently
 * provides both a standalone Network ACL Rule resource and a Network ACL resource with rules
 * defined in-line. At this time you cannot use a Network ACL with in-line rules
 * in conjunction with any Network ACL Rule resources. Doing so will cause
 * a conflict of rule settings and will overwrite rules.
 * ## Example Usage
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as aws from "@pulumi/aws";
 * const bar = new aws.ec2.NetworkAcl("bar", {vpcId: foo.id});
 * const barNetworkAclRule = new aws.ec2.NetworkAclRule("bar", {
 *     networkAclId: bar.id,
 *     ruleNumber: 200,
 *     egress: false,
 *     protocol: "tcp",
 *     ruleAction: "allow",
 *     cidrBlock: foo.cidrBlock,
 *     fromPort: 22,
 *     toPort: 22,
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_aws as aws
 * bar = aws.ec2.NetworkAcl("bar", vpc_id=foo["id"])
 * bar_network_acl_rule = aws.ec2.NetworkAclRule("bar",
 *     network_acl_id=bar.id,
 *     rule_number=200,
 *     egress=False,
 *     protocol="tcp",
 *     rule_action="allow",
 *     cidr_block=foo["cidrBlock"],
 *     from_port=22,
 *     to_port=22)
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Aws = Pulumi.Aws;
 * return await Deployment.RunAsync(() =>
 * {
 *     var bar = new Aws.Ec2.NetworkAcl("bar", new()
 *     {
 *         VpcId = foo.Id,
 *     });
 *     var barNetworkAclRule = new Aws.Ec2.NetworkAclRule("bar", new()
 *     {
 *         NetworkAclId = bar.Id,
 *         RuleNumber = 200,
 *         Egress = false,
 *         Protocol = "tcp",
 *         RuleAction = "allow",
 *         CidrBlock = foo.CidrBlock,
 *         FromPort = 22,
 *         ToPort = 22,
 *     });
 * });
 * ```
 * ```go
 * package main
 * import (
 * 	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
 * 	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
 * )
 * func main() {
 * 	pulumi.Run(func(ctx *pulumi.Context) error {
 * 		bar, err := ec2.NewNetworkAcl(ctx, "bar", &ec2.NetworkAclArgs{
 * 			VpcId: pulumi.Any(foo.Id),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = ec2.NewNetworkAclRule(ctx, "bar", &ec2.NetworkAclRuleArgs{
 * 			NetworkAclId: bar.ID(),
 * 			RuleNumber:   pulumi.Int(200),
 * 			Egress:       pulumi.Bool(false),
 * 			Protocol:     pulumi.String("tcp"),
 * 			RuleAction:   pulumi.String("allow"),
 * 			CidrBlock:    pulumi.Any(foo.CidrBlock),
 * 			FromPort:     pulumi.Int(22),
 * 			ToPort:       pulumi.Int(22),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		return nil
 * 	})
 * }
 * ```
 * ```java
 * package generated_program;
 * import com.pulumi.Context;
 * import com.pulumi.Pulumi;
 * import com.pulumi.core.Output;
 * import com.pulumi.aws.ec2.NetworkAcl;
 * import com.pulumi.aws.ec2.NetworkAclArgs;
 * import com.pulumi.aws.ec2.NetworkAclRule;
 * import com.pulumi.aws.ec2.NetworkAclRuleArgs;
 * 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) {
 *         var bar = new NetworkAcl("bar", NetworkAclArgs.builder()
 *             .vpcId(foo.id())
 *             .build());
 *         var barNetworkAclRule = new NetworkAclRule("barNetworkAclRule", NetworkAclRuleArgs.builder()
 *             .networkAclId(bar.id())
 *             .ruleNumber(200)
 *             .egress(false)
 *             .protocol("tcp")
 *             .ruleAction("allow")
 *             .cidrBlock(foo.cidrBlock())
 *             .fromPort(22)
 *             .toPort(22)
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   bar:
 *     type: aws:ec2:NetworkAcl
 *     properties:
 *       vpcId: ${foo.id}
 *   barNetworkAclRule:
 *     type: aws:ec2:NetworkAclRule
 *     name: bar
 *     properties:
 *       networkAclId: ${bar.id}
 *       ruleNumber: 200
 *       egress: false
 *       protocol: tcp
 *       ruleAction: allow
 *       cidrBlock: ${foo.cidrBlock}
 *       fromPort: 22
 *       toPort: 22
 * ```
 * 
 * > **Note:** One of either `cidr_block` or `ipv6_cidr_block` is required.
 * ## Import
 * Using the procotol's decimal value:
 * __Using `pulumi import` to import__ individual rules using `NETWORK_ACL_ID:RULE_NUMBER:PROTOCOL:EGRESS`, where `PROTOCOL` can be a decimal (such as "6") or string (such as "tcp") value. For example:
 * Using the procotol's string value:
 * ```sh
 * $ pulumi import aws:ec2/networkAclRule:NetworkAclRule my_rule acl-7aaabd18:100:tcp:false
 * ```
 * Using the procotol's decimal value:
 * ```sh
 * $ pulumi import aws:ec2/networkAclRule:NetworkAclRule my_rule acl-7aaabd18:100:6:false
 * ```
 */
public class NetworkAclRule internal constructor(
    override val javaResource: com.pulumi.aws.ec2.NetworkAclRule,
) : KotlinCustomResource(javaResource, NetworkAclRuleMapper) {
    /**
     * The network range to allow or deny, in CIDR notation (for example 172.16.0.0/24 ).
     */
    public val cidrBlock: Output?
        get() = javaResource.cidrBlock().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * Indicates whether this is an egress rule (rule is applied to traffic leaving the subnet). Default `false`.
     */
    public val egress: Output?
        get() = javaResource.egress().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * The from port to match.
     */
    public val fromPort: Output?
        get() = javaResource.fromPort().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * ICMP protocol: The ICMP code. Required if specifying ICMP for the protocolE.g., -1
     * > **NOTE:** If the value of `protocol` is `-1` or `all`, the `from_port` and `to_port` values will be ignored and the rule will apply to all ports.
     * > **NOTE:** If the value of `icmp_type` is `-1` (which results in a wildcard ICMP type), the `icmp_code` must also be set to `-1` (wildcard ICMP code).
     * > Note: For more information on ICMP types and codes, see here: https://www.iana.org/assignments/icmp-parameters/icmp-parameters.xhtml
     */
    public val icmpCode: Output?
        get() = javaResource.icmpCode().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * ICMP protocol: The ICMP type. Required if specifying ICMP for the protocolE.g., -1
     */
    public val icmpType: Output?
        get() = javaResource.icmpType().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * The IPv6 CIDR block to allow or deny.
     */
    public val ipv6CidrBlock: Output?
        get() = javaResource.ipv6CidrBlock().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * The ID of the network ACL.
     */
    public val networkAclId: Output
        get() = javaResource.networkAclId().applyValue({ args0 -> args0 })

    /**
     * The protocol. A value of -1 means all protocols.
     */
    public val protocol: Output
        get() = javaResource.protocol().applyValue({ args0 -> args0 })

    /**
     * Indicates whether to allow or deny the traffic that matches the rule. Accepted values: `allow` | `deny`
     */
    public val ruleAction: Output
        get() = javaResource.ruleAction().applyValue({ args0 -> args0 })

    /**
     * The rule number for the entry (for example, 100). ACL entries are processed in ascending order by rule number.
     */
    public val ruleNumber: Output
        get() = javaResource.ruleNumber().applyValue({ args0 -> args0 })

    /**
     * The to port to match.
     */
    public val toPort: Output?
        get() = javaResource.toPort().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })
}

public object NetworkAclRuleMapper : ResourceMapper {
    override fun supportsMappingOfType(javaResource: Resource): Boolean =
        com.pulumi.aws.ec2.NetworkAclRule::class == javaResource::class

    override fun map(javaResource: Resource): NetworkAclRule = NetworkAclRule(
        javaResource as
            com.pulumi.aws.ec2.NetworkAclRule,
    )
}

/**
 * @see [NetworkAclRule].
 * @param name The _unique_ name of the resulting resource.
 * @param block Builder for [NetworkAclRule].
 */
public suspend fun networkAclRule(
    name: String,
    block: suspend NetworkAclRuleResourceBuilder.() -> Unit,
): NetworkAclRule {
    val builder = NetworkAclRuleResourceBuilder()
    builder.name(name)
    block(builder)
    return builder.build()
}

/**
 * @see [NetworkAclRule].
 * @param name The _unique_ name of the resulting resource.
 */
public fun networkAclRule(name: String): NetworkAclRule {
    val builder = NetworkAclRuleResourceBuilder()
    builder.name(name)
    return builder.build()
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy