Skip to content

Commit 76f0da9

Browse files
committed
Updating component resource to be a more complete picture
1 parent 29a87bf commit 76f0da9

File tree

2 files changed

+104
-11
lines changed

2 files changed

+104
-11
lines changed

CLAUDE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Build/Test/Lint Commands
6+
- Build site: `make build`
7+
- Serve locally: `make serve` or `make serve-all` (with asset rebuilding)
8+
- Lint code: `make lint`
9+
- Format code: `make format`
10+
- Run tests: `make test`
11+
- Test specific programs: `ONLY_TEST="program-name" ./scripts/programs/test.sh`
12+
13+
## Code Style Guidelines
14+
- **Markdown**: Use one line per paragraph or semantic line breaks (see STYLE-GUIDE.md)
15+
- **Headings**: First level (H1) uses title case, all other headings use sentence case
16+
- **Links**: Use Hugo's `relref` shortcode for internal links: `[Text]({{< relref "/path" >}})`
17+
- **Code Examples**: Place in `/static/programs` directory with language suffix naming convention
18+
- **TypeScript/JavaScript**: Follow tsconfig.json settings - no comments unless requested
19+
- **File Structure**: Follow existing conventions for placement of new content
20+
- **Includes**: Use Hugo shortcodes for shared content across articles
21+
- **Naming**: Use lowercase for non-proper nouns (e.g., "stack" not "Stack" in text)

content/docs/iac/concepts/resources/components.md

+83-11
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ Here’s a simple component example:
4141
class MyComponent extends pulumi.ComponentResource {
4242
constructor(name, myComponentArgs, opts) {
4343
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+
});
4453
}
4554
}
4655
```
@@ -50,8 +59,19 @@ class MyComponent extends pulumi.ComponentResource {
5059

5160
```typescript
5261
class MyComponent extends pulumi.ComponentResource {
62+
bucket: aws.s3.BucketV2;
63+
5364
constructor(name: string, myComponentArgs: MyComponentArgs, opts: pulumi.ComponentResourceOptions) {
5465
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+
});
5575
}
5676
}
5777
```
@@ -71,6 +91,7 @@ class MyComponent(pulumi.ComponentResource):
7191
```go
7292
type MyComponent struct {
7393
pulumi.ResourceState
94+
Bucket *s3.BucketV2
7495
}
7596

7697
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
80101
return nil, err
81102
}
82103

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+
83117
return myComponent, nil
84118
}
85119
```
@@ -90,13 +124,20 @@ func NewMyComponent(ctx *pulumi.Context, name string, myComponentArgs MyComponen
90124
```csharp
91125
class MyComponent : Pulumi.ComponentResource
92126
{
127+
public Aws.S3.BucketV2 Bucket { get; private set; }
128+
93129
public MyComponent(string name, MyComponentArgs myComponentArgs, ComponentResourceOptions opts)
94130
: base("pkg:index:MyComponent", name, opts)
95131
{
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+
});
100141
}
101142
}
102143
```
@@ -107,14 +148,31 @@ class MyComponent : Pulumi.ComponentResource
107148
```java
108149
import com.pulumi.resources.ComponentResource;
109150
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;
110154

111155
class MyComponent extends ComponentResource {
156+
private final BucketV2 bucket;
157+
112158
public MyComponent(String name, MyComponentArgs myComponentArgs, ComponentResourceOptions opts) {
113159
super("pkg:index:MyComponent", name, null, opts);
114-
// initialization logic.
115160

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;
118176
}
119177
}
120178
```
@@ -158,8 +216,13 @@ let bucket = new aws.s3.BucketV2(`${name}-bucket`,
158216
{{% choosable language python %}}
159217

160218
```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))
163226
```
164227

165228
{{% /choosable %}}
@@ -224,8 +287,17 @@ this.registerOutputs({
224287
{{% choosable language python %}}
225288

226289
```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
229301
})
230302
```
231303

0 commit comments

Comments
 (0)