@@ -41,6 +41,15 @@ Here’s a simple component example:
41
41
class MyComponent extends pulumi .ComponentResource {
42
42
constructor (name , myComponentArgs , opts ) {
43
43
super (" pkg:index:MyComponent" , name, {}, opts);
44
+
45
+ // Create Child Resource
46
+ this .bucket = new aws.s3.BucketV2 (` ${ name} -bucket` ,
47
+ {}, { parent: this });
48
+
49
+ // Registering Component Outputs
50
+ this .registerOutputs ({
51
+ bucketDnsName: this .bucket .bucketDomainName
52
+ });
44
53
}
45
54
}
46
55
```
@@ -50,8 +59,19 @@ class MyComponent extends pulumi.ComponentResource {
50
59
51
60
``` typescript
52
61
class MyComponent extends pulumi .ComponentResource {
62
+ bucket: aws .s3 .BucketV2 ;
63
+
53
64
constructor (name : string , myComponentArgs : MyComponentArgs , opts : pulumi .ComponentResourceOptions ) {
54
65
super (" pkg:index:MyComponent" , name , {}, opts );
66
+
67
+ // Create Child Resource
68
+ this .bucket = new aws .s3 .BucketV2 (` ${name }-bucket ` ,
69
+ {}, { parent: this });
70
+
71
+ // Registering Component Outputs
72
+ this .registerOutputs ({
73
+ bucketDnsName: this .bucket .bucketDomainName
74
+ });
55
75
}
56
76
}
57
77
```
@@ -71,6 +91,7 @@ class MyComponent(pulumi.ComponentResource):
71
91
``` go
72
92
type MyComponent struct {
73
93
pulumi.ResourceState
94
+ Bucket *s3.BucketV2
74
95
}
75
96
76
97
func NewMyComponent (ctx *pulumi .Context , name string , myComponentArgs MyComponentArgs , opts ...pulumi .ResourceOption ) (*MyComponent , error ) {
@@ -80,6 +101,19 @@ func NewMyComponent(ctx *pulumi.Context, name string, myComponentArgs MyComponen
80
101
return nil , err
81
102
}
82
103
104
+ // Create Child Resource
105
+ bucket , err := s3.NewBucketV2 (ctx, fmt.Sprintf (" %s -bucket" , name),
106
+ &s3.BucketV2Args {}, pulumi.Parent (myComponent))
107
+ if err != nil {
108
+ return nil , err
109
+ }
110
+ myComponent.Bucket = bucket
111
+
112
+ // Registering Component Outputs
113
+ ctx.RegisterResourceOutputs (myComponent, pulumi.Map {
114
+ " bucketDnsName" : bucket.BucketDomainName ,
115
+ })
116
+
83
117
return myComponent, nil
84
118
}
85
119
```
@@ -90,13 +124,20 @@ func NewMyComponent(ctx *pulumi.Context, name string, myComponentArgs MyComponen
90
124
``` csharp
91
125
class MyComponent : Pulumi .ComponentResource
92
126
{
127
+ public Aws.S3.BucketV2 Bucket { get ; private set ; }
128
+
93
129
public MyComponent (string name , MyComponentArgs myComponentArgs , ComponentResourceOptions opts )
94
130
: base (" pkg:index:MyComponent" , name , opts )
95
131
{
96
- // initialization logic.
97
-
98
- // Signal to the UI that this resource has completed construction.
99
- this .RegisterOutputs ();
132
+ // Create Child Resource
133
+ this .Bucket = new Aws .S3 .BucketV2 ($" {name }-bucket" ,
134
+ new Aws .S3 .BucketV2Args (), new CustomResourceOptions { Parent = this });
135
+
136
+ // Registering Component Outputs
137
+ this .RegisterOutputs (new Dictionary <string , object >
138
+ {
139
+ { " bucketDnsName" , Bucket .BucketDomainName }
140
+ });
100
141
}
101
142
}
102
143
```
@@ -107,14 +148,31 @@ class MyComponent : Pulumi.ComponentResource
107
148
``` java
108
149
import com.pulumi.resources.ComponentResource ;
109
150
import com.pulumi.resources.ComponentResourceOptions ;
151
+ import com.pulumi.aws.s3.BucketV2 ;
152
+ import com.pulumi.aws.s3.BucketV2Args ;
153
+ import com.pulumi.resources.CustomResourceOptions ;
110
154
111
155
class MyComponent extends ComponentResource {
156
+ private final BucketV2 bucket;
157
+
112
158
public MyComponent (String name , MyComponentArgs myComponentArgs , ComponentResourceOptions opts ) {
113
159
super (" pkg:index:MyComponent" , name, null , opts);
114
- // initialization logic.
115
160
116
- // Signal to the UI that this resource has completed construction.
117
- this . registerOutputs();
161
+ // Create Child Resource
162
+ this . bucket = new BucketV2 (String . format(" %s-bucket" , name),
163
+ BucketV2Args . builder(). build(),
164
+ CustomResourceOptions . builder()
165
+ .parent(this )
166
+ .build());
167
+
168
+ // Registering Component Outputs
169
+ this . registerOutputs(Map . of(
170
+ " bucketDnsName" , bucket. bucketDomainName()
171
+ ));
172
+ }
173
+
174
+ public BucketV2 bucket () {
175
+ return this . bucket;
118
176
}
119
177
}
120
178
```
@@ -158,8 +216,13 @@ let bucket = new aws.s3.BucketV2(`${name}-bucket`,
158
216
{{% choosable language python %}}
159
217
160
218
``` python
161
- bucket = s3.BucketV2(f " { name} -bucket " ,
162
- opts = pulumi.ResourceOptions(parent = self ))
219
+ class MyComponent (pulumi .ComponentResource ):
220
+ def __init__ (self , name , my_component_args , opts = None ):
221
+ super ().__init__ (' pkg:index:MyComponent' , name, None , opts)
222
+
223
+ # Create Child Resource
224
+ self .bucket = s3.BucketV2(f " { name} -bucket " ,
225
+ opts = pulumi.ResourceOptions(parent = self ))
163
226
```
164
227
165
228
{{% /choosable %}}
@@ -224,8 +287,17 @@ this.registerOutputs({
224
287
{{% choosable language python %}}
225
288
226
289
``` python
227
- self .register_outputs({
228
- " bucketDnsName" : bucket.bucketDomainName
290
+ class MyComponent (pulumi .ComponentResource ):
291
+ def __init__ (self , name , my_component_args , opts = None ):
292
+ super ().__init__ (' pkg:index:MyComponent' , name, None , opts)
293
+
294
+ # Create Child Resource
295
+ self .bucket = s3.BucketV2(f " { name} -bucket " ,
296
+ opts = pulumi.ResourceOptions(parent = self ))
297
+
298
+ # Registering Component Outputs
299
+ self .register_outputs({
300
+ " bucketDnsName" : bucket.bucketDomainName
229
301
})
230
302
```
231
303
0 commit comments