Skip to content

Commit 26b5c83

Browse files
committed
fix: examples
1 parent cb774fd commit 26b5c83

File tree

1 file changed

+109
-93
lines changed

1 file changed

+109
-93
lines changed

docs/pulumi.md

Lines changed: 109 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -238,34 +238,33 @@ import pulumi
238238
import pulumi_ibm as ibm
239239
240240
config = pulumi.Config()
241-
region = config.require("region")
242-
resource_group = config.get("resource-group") or "default"
241+
resource_group = config.get("resource-group") or "Default"
243242
244243
# Create a Cloud Object Storage instance
245-
cos_instance = ibm.resource.Instance(
244+
cos_instance = ibm.ResourceInstance(
246245
"my-cos-instance",
247246
name="my-dev-cos-instance",
248247
service="cloud-object-storage",
249248
plan="lite",
250249
location="global",
251-
resource_group_name=resource_group,
250+
resource_group_id=resource_group,
252251
tags=["environment:dev", "managed-by:pulumi"]
253252
)
254253
255-
# Create a bucket in the COS instance
256-
cos_bucket = ibm.cos.Bucket(
254+
# Create a COS bucket
255+
cos_bucket = ibm.CosBucket(
257256
"my-bucket",
258257
bucket_name="my-unique-bucket-name",
259258
resource_instance_id=cos_instance.id,
260-
region=region,
259+
region_location="us-south",
261260
storage_class="standard",
262261
endpoint_type="public"
263262
)
264263
265-
# Export the bucket details
264+
# Output the details
266265
pulumi.export("bucket_name", cos_bucket.bucket_name)
267-
pulumi.export("bucket_region", cos_bucket.region)
268266
pulumi.export("cos_instance_id", cos_instance.id)
267+
269268
```
270269
271270
</details>
@@ -279,129 +278,146 @@ import pulumi
279278
import pulumi_ibm as ibm
280279
281280
config = pulumi.Config()
282-
region = config.require("region")
283281
284282
# Create a VPC
285-
vpc = ibm.is.Vpc(
283+
vpc = ibm.IsVpc(
286284
"my-vpc",
287285
name="my-development-vpc",
288286
resource_group=config.get("resource-group"),
289287
tags=["environment:dev"]
290288
)
291289
290+
# Create an address prefix
291+
vpc_address_prefix = ibm.IsVpcAddressPrefix(
292+
"my-address-prefix",
293+
cidr="10.0.1.0/24",
294+
vpc=vpc.is_vpc_id,
295+
zone="us-south-1"
296+
)
297+
292298
# Create a subnet
293-
subnet = ibm.is.Subnet(
299+
vpc_subnet = ibm.IsSubnet(
294300
"my-subnet",
295-
name="my-subnet",
296-
vpc=vpc.id,
297-
zone=f"{region}-1",
298-
ipv4_cidr_block="10.240.0.0/24",
299-
tags=["environment:dev"]
301+
ipv4_cidr_block="10.0.1.0/24",
302+
vpc=vpc.is_vpc_id,
303+
zone="us-south-1",
304+
opts = pulumi.ResourceOptions(
305+
depends_on=[vpc_address_prefix]
306+
)
300307
)
301308
302309
# Create a security group
303-
security_group = ibm.is.SecurityGroup(
304-
"my-security-group",
305-
name="my-security-group",
306-
vpc=vpc.id,
307-
rules=[
308-
ibm.is.SecurityGroupRuleArgs(
309-
direction="inbound",
310-
ip_version="ipv4",
311-
protocol="tcp",
312-
port_min=22,
313-
port_max=22,
314-
remote="0.0.0.0/0"
315-
),
316-
ibm.is.SecurityGroupRuleArgs(
317-
direction="inbound",
318-
ip_version="ipv4",
319-
protocol="tcp",
320-
port_min=80,
321-
port_max=80,
322-
remote="0.0.0.0/0"
323-
)
324-
]
310+
security_group = ibm.IsSecurityGroup(
311+
"my-security-group",
312+
vpc=vpc.is_vpc_id,
325313
)
326314
327-
# Export VPC details
315+
# Create Security Group Rules
316+
317+
sg_rule_1 = ibm.IsSecurityGroupRule("my-sg-rule1",
318+
group=security_group.is_security_group_id,
319+
direction="inbound",
320+
remote="127.0.0.1",
321+
icmp={
322+
"code": 20,
323+
"type": 30,
324+
})
325+
326+
sg_rule_2 = ibm.IsSecurityGroupRule("my-sg-rule2",
327+
group=security_group.is_security_group_id,
328+
direction="inbound",
329+
remote="127.0.0.1",
330+
udp={
331+
"port_min": 805,
332+
"port_max": 807,
333+
})
334+
335+
sg_rule_3 = ibm.IsSecurityGroupRule("my-sg-rule3",
336+
group=security_group.is_security_group_id,
337+
direction="outbound",
338+
remote="127.0.0.1",
339+
tcp={
340+
"port_min": 8080,
341+
"port_max": 8080,
342+
})
343+
344+
# Output VPC details
328345
pulumi.export("vpc_id", vpc.id)
329346
pulumi.export("vpc_name", vpc.name)
330-
pulumi.export("subnet_id", subnet.id)
347+
pulumi.export("address_prefix", vpc_address_prefix.id)
348+
pulumi.export("subnet_id", vpc_subnet.id)
331349
pulumi.export("security_group_id", security_group.id)
332350
333351
```
334352
335353
</details>
336354
337-
338355
<details>
339-
<summary> Example 3: IAM Service ID and API Key</summary>
356+
<summary> Example 3: Red Hat OpenShift Cluster with a default worker pool with one worker node. </summary>
340357
<br/>
341358
342359
```py
343360
import pulumi
344361
import pulumi_ibm as ibm
345362
346-
# Create a service ID
347-
service_id = ibm.iam.ServiceId(
348-
"my-service-id",
349-
name="my-app-service-id",
350-
description="Service ID for my application"
351-
)
352-
353-
# Create an API key for the service ID
354-
api_key = ibm.iam.ServiceApiKey(
355-
"my-api-key",
356-
name="my-app-api-key",
357-
iam_service_id=service_id.iam_id,
358-
description="API key for my application"
359-
)
360-
361-
# Export the API key (be careful with this in production!)
362-
pulumi.export("api_key_value", api_key.apikey)
363-
```
363+
config = pulumi.Config()
364364
365-
</details>
365+
# Create a VPC
366366
367-
<details>
368-
<summary> Example 4: Kubernetes Cluster with Node Pool </summary>
369-
<br/>
367+
vpc = ibm.IsVpc(
368+
"my-vpc",
369+
name="gen2-vpc",
370+
resource_group=config.get("resource-group"),
371+
tags=["environment:dev"]
372+
)
370373
371-
```py
372-
import pulumi
373-
import pulumi_ibm as ibm
374+
# Create an address prefix
375+
vpc_address_prefix = ibm.IsVpcAddressPrefix(
376+
"my-address-prefix",
377+
cidr="10.0.1.0/24",
378+
vpc=vpc.is_vpc_id,
379+
zone="us-south-1"
380+
)
374381
375-
config = pulumi.Config()
382+
# Create a subnet
383+
vpc_subnet = ibm.IsSubnet(
384+
"my-subnet",
385+
ipv4_cidr_block="10.0.1.0/24",
386+
vpc=vpc.is_vpc_id,
387+
zone="us-south-1",
388+
opts = pulumi.ResourceOptions(
389+
depends_on=[vpc_address_prefix]
390+
)
391+
)
376392
377-
# Create a Kubernetes cluster
378-
cluster = ibm.container.VpcCluster(
379-
"my-cluster",
380-
name="my-k8s-cluster",
381-
vpc_id=config.require("vpc_id"),
382-
subnet_ids=config.require_object("subnet_ids"),
383-
kube_version=config.get("kube_version") or "1.28",
384-
flavor=config.get("flavor") or "bx2.4x16",
385-
worker_count=config.get_int("worker_count") or 2,
386-
resource_group_id=config.get("resource_group_id"),
387-
tags=["environment:dev", "managed-by:pulumi"]
393+
# Create a COS instance
394+
cos_instance = ibm.ResourceInstance("cosInstance",
395+
service="cloud-object-storage",
396+
plan="standard",
397+
location="global"
388398
)
389399
390-
# Create a worker pool
391-
worker_pool = ibm.container.VpcWorkerPool(
392-
"my-worker-pool",
393-
cluster=cluster.id,
394-
flavor=config.get("worker_pool_flavor") or "bx2.4x16",
395-
worker_count=config.get_int("worker_pool_count") or 3,
396-
name="additional-worker-pool",
397-
vpc_id=config.require("vpc_id"),
398-
subnet_ids=config.require_object("subnet_ids")
400+
# Create an OCP Cluster
401+
cluster = ibm.ContainerVpcCluster("my-ocp-cluster",
402+
vpc_id=vpc.is_vpc_id,
403+
kube_version="4.18.24_openshift",
404+
flavor="bx2.16x64",
405+
worker_count=2,
406+
entitlement="cloud_pak",
407+
cos_instance_crn=cos_instance.resource_instance_id,
408+
resource_group_id=config.get("resource-group"),
409+
zones=[{
410+
"subnet_id": vpc_subnet.id,
411+
"name": "us-south-1",
412+
}]
399413
)
400414
401-
# Export cluster details
402-
pulumi.export("cluster_id", cluster.id)
403-
pulumi.export("cluster_name", cluster.name)
404-
pulumi.export("kube_version", cluster.kube_version)
415+
# Outputs
416+
pulumi.export("vpc_id", vpc.id)
417+
pulumi.export("vpc_name", vpc.name)
418+
pulumi.export("subnet_id", vpc_subnet.id)
419+
pulumi.export("ocp_cluster_id", cluster.id)
420+
405421
```
406422
407423
</details>

0 commit comments

Comments
 (0)