Repository: pulumi/pulumi-awsx
Pull request #899 (2022-08-23 09:17:27)

awsx.ec2.Vpc: Allow setting tags in subnetsSpecs
Fixes: #889


danielrbradley: Looks like you just need to re-generate the SDKs

Patch:
diff --git a/awsx/ec2/subnetDistributor.ts b/awsx/ec2/subnetDistributor.ts
index d47c1249..031942df 100644
--- a/awsx/ec2/subnetDistributor.ts
+++ b/awsx/ec2/subnetDistributor.ts
@@ -15,6 +15,7 @@
 // Code adapted from https://github.com/jen20/pulumi-aws-vpc/blob/master/nodejs/src/subnetDistributor.ts
 // and used in accordance with MPL v2.0 license
 
+import * as pulumi from "@pulumi/pulumi";
 import { SubnetSpecInputs, SubnetTypeInputs } from "../schema-types";
 
 export interface SubnetSpec {
@@ -22,6 +23,9 @@ export interface SubnetSpec {
   type: SubnetTypeInputs;
   azName: string;
   subnetName: string;
+  tags?: pulumi.Input<{
+    [key: string]: pulumi.Input<string>;
+  }>;
 }
 
 export function getSubnetSpecs(
@@ -70,6 +74,7 @@ export function getSubnetSpecs(
         cidrBlock: privateSubnetCidrBlock,
         type: "Private",
         subnetName: `${vpcName}-${privateSubnetsIn[j].name ?? "private"}-${i + 1}`,
+        tags: privateSubnetsIn[j].tags,
       });
     }
 
@@ -94,6 +99,7 @@ export function getSubnetSpecs(
         cidrBlock: publicSubnetCidrBlock,
         type: "Public",
         subnetName: `${vpcName}-${publicSubnetsIn[j].name ?? "public"}-${i + 1}`,
+        tags: publicSubnetsIn[j].tags,
       });
     }
 
@@ -129,6 +135,7 @@ export function getSubnetSpecs(
         cidrBlock: isolatedSubnetCidrBlock,
         type: "Isolated",
         subnetName: `${vpcName}-${isolatedSubnetsIn[j].name ?? "isolated"}-${i + 1}`,
+        tags: isolatedSubnetsIn[j].tags,
       });
     }
 
diff --git a/awsx/schema-types.ts b/awsx/schema-types.ts
index 3bff1e4a..22af4d51 100644
--- a/awsx/schema-types.ts
+++ b/awsx/schema-types.ts
@@ -549,11 +549,13 @@ export type NatGatewayStrategyOutputs = "None" | "Single" | "OnePerAz";
 export interface SubnetSpecInputs {
     readonly cidrMask?: number;
     readonly name?: string;
+    readonly tags?: pulumi.Input<Record<string, pulumi.Input<string>>>;
     readonly type: SubnetTypeInputs;
 }
 export interface SubnetSpecOutputs {
     readonly cidrMask?: number;
     readonly name?: string;
+    readonly tags?: pulumi.Output<Record<string, string>>;
     readonly type: SubnetTypeOutputs;
 }
 export type SubnetTypeInputs = "Public" | "Private" | "Isolated";
diff --git a/awsx/schema.json b/awsx/schema.json
index 220e02ed..6c56b5db 100644
--- a/awsx/schema.json
+++ b/awsx/schema.json
@@ -510,6 +510,13 @@
                     "plain": true,
                     "description": "The subnet's name. Will be templated upon creation."
                 },
+                "tags": {
+                    "type": "object",
+                    "additionalProperties": {
+                        "type": "string"
+                    },
+                    "description": "A map of tags to assign to the resource."
+                },
                 "type": {
                     "$ref": "#/types/awsx:ec2:SubnetType",
                     "plain": true,
diff --git a/schemagen/pkg/gen/ec2.go b/schemagen/pkg/gen/ec2.go
index 93ed89e1..9c3169fd 100644
--- a/schemagen/pkg/gen/ec2.go
+++ b/schemagen/pkg/gen/ec2.go
@@ -313,6 +313,13 @@ func subnetSpecType() schema.ComplexTypeSpec {
 					Description: "The bitmask for the subnet's CIDR block.",
 					TypeSpec:    plainInt(),
 				},
+				"tags": {
+					TypeSpec: schema.TypeSpec{
+						Type:                 "object",
+						AdditionalProperties: &schema.TypeSpec{Type: "string"},
+					},
+					Description: "A map of tags to assign to the resource.",
+				},
 			},
 			Required: []string{
 				"type",
diff --git a/sdk/dotnet/Ec2/Inputs/SubnetSpecArgs.cs b/sdk/dotnet/Ec2/Inputs/SubnetSpecArgs.cs
index a61e3c65..9fe1233b 100644
--- a/sdk/dotnet/Ec2/Inputs/SubnetSpecArgs.cs
+++ b/sdk/dotnet/Ec2/Inputs/SubnetSpecArgs.cs
@@ -27,6 +27,18 @@ namespace Pulumi.Awsx.Ec2.Inputs
         [Input("name")]
         public string? Name { get; set; }
 
+        [Input("tags")]
+        private InputMap<string>? _tags;
+
+        /// <summary>
+        /// A map of tags to assign to the resource.
+        /// </summary>
+        public InputMap<string> Tags
+        {
+            get => _tags ?? (_tags = new InputMap<string>());
+            set => _tags = value;
+        }
+
         /// <summary>
         /// The type of subnet.
         /// </summary>
diff --git a/sdk/go/awsx/ec2/pulumiTypes.go b/sdk/go/awsx/ec2/pulumiTypes.go
index dbae094d..4f2f7731 100644
--- a/sdk/go/awsx/ec2/pulumiTypes.go
+++ b/sdk/go/awsx/ec2/pulumiTypes.go
@@ -175,6 +175,8 @@ type SubnetSpec struct {
 	CidrMask *int `pulumi:"cidrMask"`
 	// The subnet's name. Will be templated upon creation.
 	Name *string `pulumi:"name"`
+	// A map of tags to assign to the resource.
+	Tags map[string]string `pulumi:"tags"`
 	// The type of subnet.
 	Type SubnetType `pulumi:"type"`
 }
@@ -196,6 +198,8 @@ type SubnetSpecArgs struct {
 	CidrMask *int `pulumi:"cidrMask"`
 	// The subnet's name. Will be templated upon creation.
 	Name *string `pulumi:"name"`
+	// A map of tags to assign to the resource.
+	Tags pulumi.StringMapInput `pulumi:"tags"`
 	// The type of subnet.
 	Type SubnetType `pulumi:"type"`
 }
@@ -262,6 +266,11 @@ func (o SubnetSpecOutput) Name() pulumi.StringPtrOutput {
 	return o.ApplyT(func(v SubnetSpec) *string { return v.Name }).(pulumi.StringPtrOutput)
 }
 
+// A map of tags to assign to the resource.
+func (o SubnetSpecOutput) Tags() pulumi.StringMapOutput {
+	return o.ApplyT(func(v SubnetSpec) map[string]string { return v.Tags }).(pulumi.StringMapOutput)
+}
+
 // The type of subnet.
 func (o SubnetSpecOutput) Type() SubnetTypeOutput {
 	return o.ApplyT(func(v SubnetSpec) SubnetType { return v.Type }).(SubnetTypeOutput)
diff --git a/sdk/java/src/main/java/com/pulumi/awsx/ec2/inputs/SubnetSpecArgs.java b/sdk/java/src/main/java/com/pulumi/awsx/ec2/inputs/SubnetSpecArgs.java
index 90239be7..a81084f7 100644
--- a/sdk/java/src/main/java/com/pulumi/awsx/ec2/inputs/SubnetSpecArgs.java
+++ b/sdk/java/src/main/java/com/pulumi/awsx/ec2/inputs/SubnetSpecArgs.java
@@ -4,9 +4,11 @@
 package com.pulumi.awsx.ec2.inputs;
 
 import com.pulumi.awsx.ec2.enums.SubnetType;
+import com.pulumi.core.Output;
 import com.pulumi.core.annotations.Import;
 import java.lang.Integer;
 import java.lang.String;
+import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
 import javax.annotation.Nullable;
@@ -50,6 +52,21 @@ public final class SubnetSpecArgs extends com.pulumi.resources.ResourceArgs {
         return Optional.ofNullable(this.name);
     }
 
+    /**
+     * A map of tags to assign to the resource.
+     * 
+     */
+    @Import(name="tags")
+    private @Nullable Output<Map<String,String>> tags;
+
+    /**
+     * @return A map of tags to assign to the resource.
+     * 
+     */
+    public Optional<Output<Map<String,String>>> tags() {
+        return Optional.ofNullable(this.tags);
+    }
+
     /**
      * The type of subnet.
      * 
@@ -70,6 +87,7 @@ public final class SubnetSpecArgs extends com.pulumi.resources.ResourceArgs {
     private SubnetSpecArgs(SubnetSpecArgs $) {
         this.cidrMask = $.cidrMask;
         this.name = $.name;
+        this.tags = $.tags;
         this.type = $.type;
     }
 
@@ -113,6 +131,27 @@ public final class SubnetSpecArgs extends com.pulumi.resources.ResourceArgs {
             return this;
         }
 
+        /**
+         * @param tags A map of tags to assign to the resource.
+         * 
+         * @return builder
+         * 
+         */
+        public Builder tags(@Nullable Output<Map<String,String>> tags) {
+            $.tags = tags;
+            return this;
+        }
+
+        /**
+         * @param tags A map of tags to assign to the resource.
+         * 
+         * @return builder
+         * 
+         */
+        public Builder tags(Map<String,String> tags) {
+            return tags(Output.of(tags));
+        }
+
         /**
          * @param type The type of subnet.
          * 
diff --git a/sdk/nodejs/types/input.ts b/sdk/nodejs/types/input.ts
index af5fdf04..e666125f 100644
--- a/sdk/nodejs/types/input.ts
+++ b/sdk/nodejs/types/input.ts
@@ -386,6 +386,10 @@ export namespace ec2 {
          * The subnet's name. Will be templated upon creation.
          */
         name?: string;
+        /**
+         * A map of tags to assign to the resource.
+         */
+        tags?: pulumi.Input<{[key: string]: pulumi.Input<string>}>;
         /**
          * The type of subnet.
          */
diff --git a/sdk/python/pulumi_awsx/ec2/_inputs.py b/sdk/python/pulumi_awsx/ec2/_inputs.py
index 424ede57..9cb8b270 100644
--- a/sdk/python/pulumi_awsx/ec2/_inputs.py
+++ b/sdk/python/pulumi_awsx/ec2/_inputs.py
@@ -59,18 +59,22 @@ class SubnetSpecArgs:
     def __init__(__self__, *,
                  type: 'SubnetType',
                  cidr_mask: Optional[int] = None,
-                 name: Optional[str] = None):
+                 name: Optional[str] = None,
+                 tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None):
         """
         Configuration for a VPC subnet.
         :param 'SubnetType' type: The type of subnet.
         :param int cidr_mask: The bitmask for the subnet's CIDR block.
         :param str name: The subnet's name. Will be templated upon creation.
+        :param pulumi.Input[Mapping[str, pulumi.Input[str]]] tags: A map of tags to assign to the resource.
         """
         pulumi.set(__self__, "type", type)
         if cidr_mask is not None:
             pulumi.set(__self__, "cidr_mask", cidr_mask)
         if name is not None:
             pulumi.set(__self__, "name", name)
+        if tags is not None:
+            pulumi.set(__self__, "tags", tags)
 
     @property
     @pulumi.getter
@@ -108,6 +112,18 @@ class SubnetSpecArgs:
     def name(self, value: Optional[str]):
         pulumi.set(self, "name", value)
 
+    @property
+    @pulumi.getter
+    def tags(self) -> Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]]:
+        """
+        A map of tags to assign to the resource.
+        """
+        return pulumi.get(self, "tags")
+
+    @tags.setter
+    def tags(self, value: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]]):
+        pulumi.set(self, "tags", value)
+
 
 @pulumi.input_type
 class VpcEndpointSpecArgs:


Test patch:
diff --git a/awsx/ec2/subnetDistributor.test.ts b/awsx/ec2/subnetDistributor.test.ts
index 440221e5..04bbb1ac 100644
--- a/awsx/ec2/subnetDistributor.test.ts
+++ b/awsx/ec2/subnetDistributor.test.ts
@@ -71,6 +71,10 @@ describe("getSubnetSpecs", () => {
           cidrMask: 19,
           type: type,
           name: "foo",
+          tags: {
+            Name: "test",
+            Owner: "user1",
+          },
         },
       ];
 
@@ -80,18 +84,30 @@ describe("getSubnetSpecs", () => {
           cidrBlock: "10.0.0.0/19",
           azName: "us-east-1a",
           subnetName: "vpcname-foo-1",
+          tags: {
+            Name: "test",
+            Owner: "user1",
+          },
         },
         {
           type: type,
           cidrBlock: "10.0.64.0/19",
           azName: "us-east-1b",
           subnetName: "vpcname-foo-2",
+          tags: {
+            Name: "test",
+            Owner: "user1",
+          },
         },
         {
           type: type,
           cidrBlock: "10.0.128.0/19",
           azName: "us-east-1c",
           subnetName: "vpcname-foo-3",
+          tags: {
+            Name: "test",
+            Owner: "user1",
+          },
         },
       ];
 
diff --git a/awsx/ec2/subnetsIntegration.test.ts b/awsx/ec2/subnetsIntegration.test.ts
index 8e84dd39..633f4a11 100644
--- a/awsx/ec2/subnetsIntegration.test.ts
+++ b/awsx/ec2/subnetsIntegration.test.ts
@@ -69,8 +69,6 @@ describe("subnet creation integration tests", () => {
       inputs,
     );
 
-    console.log(JSON.stringify(subnetSpecs));
-
     expect(getOverlappingSubnets(subnetSpecs)).toEqual([]);
   });