Skip to content

Commit

Permalink
Update example aws getami (#316)
Browse files Browse the repository at this point in the history
* Update the updated scalafmt.conf
* Update examples/aws-webserver
* Update logger integration test
  • Loading branch information
pawelprazak authored Dec 1, 2023
1 parent 6c688a9 commit 33ea5a6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ align.openParenCallSite = false
align.openParenDefnSite = false
align.tokens = [{code = "=>", owner = "Case"}, "<-", "%", "%%", "="]
indent.defnSite = 2
maxColumn = 120
maxColumn = 140

rewrite.scala3.insertEndMarkerMinLines = 40
27 changes: 22 additions & 5 deletions examples/aws-webserver/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ import besom.api.tls
val myIp = getExternalIp
val port = 80

// Get the id for the latest Amazon Linux AMI
val ami = ec2.getAmi(
ec2.GetAmiArgs(
filters = List(
GetAmiFilterArgs(
name = "name",
values = List("amzn2-ami-hvm-*-x86_64-ebs")
)
),
owners = List("137112412989"), // Amazon
mostRecent = true
)
)

// Create a new security group for port 80.
val securityGroup = ec2.SecurityGroup(
"web-secgrp",
Expand Down Expand Up @@ -71,14 +85,14 @@ import besom.api.tls
|rpm --import https://yum.corretto.aws/corretto.key
|yum install -y java-21-amazon-corretto-devel
|echo "Hello, World!" > /srv/index.html
|nohup jwebserver -d /srv -b 0.0.0.0 -p $port &
|nohup /usr/lib/jvm/java-21-amazon-corretto/bin/jwebserver -d /srv -b 0.0.0.0 -p $port &
|""".stripMargin

// Create a server instance
val server = ec2.Instance(
"web-server-www",
ec2.InstanceArgs(
ami = "ami-01342111f883d5e4e",
ami = ami.id,
instanceType = ec2.enums.InstanceType.T2_Micro.value, // t2.micro is available in the AWS free tier
vpcSecurityGroupIds = List(securityGroup.id), // reference the group object above
keyName = keyPair.keyName,
Expand All @@ -91,14 +105,17 @@ import besom.api.tls
server: ec2.Instance <- server
_ <- sshKey
_ <- keyPair
_ <- p"Connect to SSH the first time: pulumi stack output privateKey --show-secrets > key_rsa && chmod 400 key_rsa && ssh -i key_rsa ${userName}@${server.publicIp}".map(log.info(_))
_ <- log.info("Connect to SSH: ssh -i key_rsa ec2-user@$(pulumi stack output publicIp)")
_ <- log.info("Connect to HTTP: open http://$(pulumi stack output publicHostName)")
_ <-
p"Connect to SSH the first time: pulumi stack output privateKey --show-secrets > key_rsa && chmod 400 key_rsa && ssh -i key_rsa ${userName}@${server.publicIp}"
.flatMap(log.info(_))
_ <- log.info("Connect to SSH: ssh -i key_rsa ec2-user@$(pulumi stack output publicIp)")
_ <- log.info("Connect to HTTP: open http://$(pulumi stack output publicHostName)")
} yield Pulumi.exports(
publicKey = publicKey,
privateKey = privateKey,
publicIp = server.publicIp,
publicHostName = server.publicDns,
ami = ami.id
)
}

Expand Down
10 changes: 5 additions & 5 deletions examples/aws-webserver/project.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//> using scala "3.3.1"
//> using plugin "org.virtuslab::besom-compiler-plugin:0.1.0"
//> using dep "org.virtuslab::besom-core:0.1.0"
//> using dep "org.virtuslab::besom-aws:6.2.1-core.0.1.0"
//> using dep "org.virtuslab::besom-tls:4.11.0-core.0.1.0"
//> using scala 3.3.1
//> using options -Werror -Wunused:all -Wvalue-discard -Wnonunit-statement
//> using plugin org.virtuslab::besom-compiler-plugin:0.1.0
//> using dep org.virtuslab::besom-core:0.1.1-SNAPSHOT
//> using dep org.virtuslab::besom-aws:6.12.0-core.0.1.1-SNAPSHOT
//> using dep org.virtuslab::besom-tls:4.11.0-core.0.1.1-SNAPSHOT
1 change: 1 addition & 0 deletions integration-tests/CoreTests.test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CoreTests extends munit.FunSuite {
val result = pulumi.up(ctx.stackName).call(cwd = ctx.testDir, env = ctx.env)
val output = result.out.text()
assert(output.contains("Nothing here yet. It's waiting for you!"), s"Output:\n$output\n")
assert(output.contains("Interpolated value"), s"Output:\n$output\n")
assert(result.exitCode == 0)
}

Expand Down
1 change: 1 addition & 0 deletions integration-tests/resources/logger-example/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import besom.*
@main def run = Pulumi.run {
for
_ <- log.warn("Nothing here yet. It's waiting for you!")
_ <- p"Interpolated ${Output("value")}".flatMap(log.info(_))
yield exports()
}

0 comments on commit 33ea5a6

Please sign in to comment.