Skip to content

Commit db52bd9

Browse files
authored
Add yaml examples (#1211)
* Add YAML examples * Add cue examples
1 parent d67b1c3 commit db52bd9

File tree

39 files changed

+1158
-0
lines changed

39 files changed

+1158
-0
lines changed

aws-yaml-cue-eks/Pulumi.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: cue
2+
runtime:
3+
name: yaml
4+
options:
5+
compiler: cue export
6+
description: CUE Example

aws-yaml-cue-eks/aws/eks.cue

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package eks
2+
3+
#EksCluster: {
4+
type: "eks:Cluster"
5+
properties: {
6+
instanceType: *"t2.medium" | "t3.medium"
7+
desiredCapacity: int | *2
8+
minSize: int | *1
9+
maxSize: int | *2
10+
}
11+
}

aws-yaml-cue-eks/cue.mod/module.cue

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module: "examples.pulumi.com/yaml-eks"

aws-yaml-cue-eks/main.cue

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package main
2+
3+
import "examples.pulumi.com/yaml-eks/aws:eks"
4+
5+
resources: {
6+
rawkode: eks.#EksCluster
7+
stack72: eks.#EksCluster & {
8+
properties: {
9+
instanceType: "t2.medium"
10+
desiredCapacity: 4
11+
maxSize: 8
12+
}
13+
}
14+
}

aws-yaml-eks/Pulumi.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: aws-eks
2+
runtime: yaml
3+
description: An EKS cluster
4+
variables:
5+
vpcId:
6+
Fn::Invoke:
7+
Function: aws:ec2:getVpc
8+
Arguments:
9+
default: true
10+
Return: id
11+
subnetIds:
12+
Fn::Invoke:
13+
Function: aws:ec2:getSubnetIds
14+
Arguments:
15+
vpcId: ${vpcId}
16+
Return: ids
17+
resources:
18+
cluster:
19+
type: eks:Cluster
20+
properties:
21+
vpcId: ${vpcId}
22+
subnetIds: ${subnetIds}
23+
instanceType: "t2.medium"
24+
desiredCapacity: 2
25+
minSize: 1
26+
maxSize: 2
27+
outputs:
28+
kubeconfig: ${cluster.kubeconfig}

aws-yaml-eks/README.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
# Amazon EKS Cluster
3+
4+
This example deploys an EKS Kubernetes cluster inside the default AWS VPC.
5+
6+
## Deploying the App
7+
8+
To deploy your infrastructure, follow the below steps.
9+
10+
## Prerequisites
11+
12+
1. [Install Pulumi](https://www.pulumi.com/docs/get-started/install/)
13+
1. [Configure Pulumi for AWS](https://www.pulumi.com/docs/intro/cloud-providers/aws/setup/)
14+
15+
## Deploying and running the program
16+
17+
1. Create a new stack:
18+
19+
```
20+
$ pulumi stack init dev
21+
```
22+
23+
1. Set the AWS region:
24+
25+
```
26+
$ pulumi config set aws:region us-east-2
27+
```
28+
29+
1. Run `pulumi up` to preview and deploy changes:
30+
31+
```
32+
$ pulumi up
33+
Previewing changes:
34+
...
35+
36+
Performing changes:
37+
...
38+
Resources:
39+
+ 28 created
40+
41+
Duration: 10m0s
42+
```
43+
44+
1. Check the deployed kubeconfig:
45+
46+
```
47+
$ pulumi stack output kubeconfig
48+
{"apiVersion":"v1","clusters":[{"cluster":{"certificate-authority-data":"LS0tLS1CRUdJTiBDR...
49+
```

aws-yaml-static-website/Pulumi.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: aws-native-static-website
2+
runtime: yaml
3+
description: A static website hosted on AWS S3
4+
resources:
5+
site-bucket:
6+
type: aws-native:s3:Bucket
7+
properties:
8+
websiteConfiguration:
9+
indexDocument: index.html
10+
index.html:
11+
type: aws:s3:BucketObject
12+
properties:
13+
bucket: ${site-bucket}
14+
source:
15+
Fn::FileAsset: ./www/index.html
16+
acl: public-read
17+
contentType: text/html
18+
favicon.png:
19+
type: aws:s3:BucketObject
20+
properties:
21+
bucket: ${site-bucket}
22+
source:
23+
Fn::FileAsset: ./www/favicon.png
24+
acl: public-read
25+
contentType: image/png
26+
bucketPolicy:
27+
type: aws:s3:BucketPolicy
28+
properties:
29+
bucket: ${site-bucket}
30+
policy: |
31+
{
32+
"Version": "2012-10-17",
33+
"Statement": [
34+
{
35+
"Effect": "Allow",
36+
"Principal": "*",
37+
"Action": ["s3:GetObject"],
38+
"Resource": ["${site-bucket.arn}/*"]
39+
}
40+
]
41+
}
42+
outputs:
43+
bucketName: ${site-bucket.bucketName}
44+
websiteUrl: ${site-bucket.websiteURL}

aws-yaml-static-website/README.md

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new?template=https://github.com/pulumi/examples/blob/master/aws-native-ts-s3-folder/README.md)
2+
3+
# Host a Static Website on Amazon S3 with the AWS Native Provider
4+
5+
A static website that uses [S3's website support](https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html).
6+
For a detailed walkthrough of this example, see the tutorial [Static Website on AWS S3](https://www.pulumi.com/docs/tutorials/aws/s3-website/).
7+
8+
Note: Some resources are not yet supported by the Native AWS provider, so we are using both the Native
9+
and Classic provider in this example. The resources will be updated to use native resources as they are
10+
available in AWS's Cloud Control API.
11+
12+
## Deploying and running the program
13+
14+
Note: some values in this example will be different from run to run. These values are indicated
15+
with `***`.
16+
17+
1. Install required plugins:
18+
19+
```bash
20+
$ pulumi plugin install resource aws 4.37.3
21+
$ pulumi plugin install resource aws-native 0.11.0
22+
```
23+
24+
1. Create a new stack:
25+
26+
```bash
27+
$ pulumi stack init dev
28+
```
29+
30+
1. Set the AWS region:
31+
32+
Either using an environment variable
33+
```bash
34+
$ export AWS_REGION=us-west-2
35+
```
36+
37+
Or with the stack config
38+
```bash
39+
$ pulumi config set aws:region us-west-2
40+
$ pulumi config set aws-native:region us-west-2
41+
```
42+
43+
1. Run `pulumi up` to preview and deploy changes. After the preview is shown you will be
44+
prompted if you want to continue or not.
45+
46+
```bash
47+
$ pulumi up
48+
Previewing update (dev)
49+
...
50+
51+
Updating (dev)
52+
53+
View Live: https://app.pulumi.com/***/aws-native-ts-s3-folder/dev/updates/1
54+
55+
Type Name Status
56+
+ pulumi:pulumi:Stack aws-native-ts-s3-folder-dev created
57+
+ ├─ aws-native:s3:Bucket s3-website-bucket created
58+
+ ├─ aws:s3:BucketPolicy bucketPolicy created
59+
+ ├─ aws:s3:BucketObject index.html created
60+
+ └─ aws:s3:BucketObject favicon.png created
61+
62+
Outputs:
63+
bucketName: "***"
64+
websiteUrl: "http://***.s3-website-us-west-2.amazonaws.com"
65+
66+
Resources:
67+
+ 5 created
68+
69+
Duration: ***
70+
```
71+
72+
1. To see the resources that were created, run `pulumi stack output`:
73+
74+
```bash
75+
$ pulumi stack output
76+
Current stack outputs (2):
77+
OUTPUT VALUE
78+
bucketName ***
79+
websiteUrl http://***.s3-website-us-west-2.amazonaws.com
80+
```
81+
82+
1. To see that the S3 objects exist, you can either use the AWS Console or the AWS CLI:
83+
84+
```bash
85+
$ aws s3 ls $(pulumi stack output bucketName)
86+
2021-09-30 15:27:58 13731 favicon.png
87+
2021-09-30 15:27:58 198 index.html
88+
```
89+
90+
1. Open the site URL in a browser to see both the rendered HTML and the favicon:
91+
92+
```bash
93+
$ pulumi stack output websiteUrl
94+
***.s3-website-us-west-2.amazonaws.com
95+
```
96+
97+
![Hello S3 example](https://user-images.githubusercontent.com/274700/116912066-9384e300-abfc-11eb-8130-dbcff512a9de.png)
98+
99+
1. To clean up resources, run `pulumi destroy` and answer the confirmation question at the prompt.
13.4 KB
Loading
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<html>
2+
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Hello, Pulumi!</title>
6+
<link href="favicon.png" rel="icon" type="image/png" />
7+
</head>
8+
9+
<body>
10+
<h1>Hello, S3!</h1>
11+
<p>Made with ❤️ with <a href="https://pulumi.com">Pulumi</a></p>
12+
<p>This file is served from Amazon S3.</p>
13+
</body>
14+
15+
</html>

azure-yaml-app-service/Pulumi.yaml

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: azure-app-service
2+
runtime: yaml
3+
description: A static website hosted on AWS S3
4+
configuration:
5+
sqlAdmin:
6+
type: String
7+
default: pulumi
8+
variables:
9+
blobAccessToken:
10+
Fn::Invoke:
11+
Function: azure-native:storage:listStorageAccountServiceSAS
12+
Arguments:
13+
accountName: ${sa.name}
14+
protocols: https
15+
sharedAccessStartTime: '2022-01-01'
16+
sharedAccessExpiryTime: '2030-01-01'
17+
resource: c
18+
resourceGroupName: ${appservicegroup.name}
19+
permissions: r
20+
canonicalizedResource: /blob/${sa.name}/${container.name}
21+
contentType: application/json
22+
cacheControl: max-age=5
23+
contentDisposition: inline
24+
contentEncoding: deflate
25+
Return: serviceSasToken
26+
resources:
27+
appservicegroup:
28+
type: azure-native:resources:ResourceGroup
29+
sa:
30+
type: azure-native:storage:StorageAccount
31+
properties:
32+
resourceGroupName: ${appservicegroup.name}
33+
kind: 'StorageV2'
34+
sku: { name: 'Standard_LRS' }
35+
appserviceplan:
36+
type: azure-native:web:AppServicePlan
37+
properties:
38+
resourceGroupName: ${appservicegroup.name}
39+
kind: App
40+
sku:
41+
name: B1
42+
tier: Basic
43+
container:
44+
type: azure-native:storage:BlobContainer
45+
properties:
46+
resourceGroupName: ${appservicegroup.name}
47+
accountName: ${sa.name}
48+
publicAccess: None
49+
blob:
50+
type: azure-native:storage:Blob
51+
properties:
52+
resourceGroupName: ${appservicegroup.name}
53+
accountName: ${sa.name}
54+
containerName: ${container.name}
55+
type: 'Block'
56+
source:
57+
Fn::FileArchive: ./www
58+
appInsights:
59+
type: azure-native:insights:Component
60+
properties:
61+
resourceGroupName: ${appservicegroup.name}
62+
applicationType: web
63+
kind: web
64+
sqlPassword:
65+
type: random:RandomPassword
66+
properties:
67+
length: 16
68+
special: true
69+
sqlServer:
70+
type: azure-native:sql:Server
71+
properties:
72+
resourceGroupName: ${appservicegroup.name}
73+
administratorLogin: ${sqlAdmin}
74+
administratorLoginPassword: ${sqlPassword.result}
75+
version: '12.0'
76+
db:
77+
type: azure-native:sql:Database
78+
properties:
79+
resourceGroupName: ${appservicegroup.name}
80+
serverName: ${sqlServer.name}
81+
sku: { name: 'S0' }
82+
83+
app:
84+
type: azure-native:web:WebApp
85+
properties:
86+
resourceGroupName: ${appservicegroup.name}
87+
serverFarmId: ${appserviceplan}
88+
siteConfig:
89+
appSettings:
90+
- name: WEBSITE_RUN_FROM_PACKAGE
91+
value: https://${sa.name}.blob.core.windows.net/${container.name}/${blob.name}?${blobAccessToken}
92+
- name: APPINSIGHTS_INSTRUMENTATIONKEY
93+
value: ${appInsights.instrumentationKey}
94+
- name: APPLICATIONINSIGHTS_CONNECTION_STRING
95+
value: InstrumentationKey=${appInsights.instrumentationKey}
96+
- name: ApplicationInsightsAgent_EXTENSION_VERSION
97+
value: ~2
98+
connectionStrings:
99+
- name: db
100+
type: SQLAzure
101+
connectionString: Server= tcp:${sqlServer.name}.database.windows.net;initial catalog=${db.name};userID=${sqlAdmin};password=${sqlPassword.result};Min Pool Size=0;Max Pool Size=30;Persist Security Info=true;
102+
outputs:
103+
endpoint: ${app.defaultHostName}

0 commit comments

Comments
 (0)