diff --git a/README.md b/README.md index 7c3cd08047..428aa692d6 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ Choose a language: - [google](./examples/typescript/google) - [google-cloudrun](./examples/typescript/google-cloudrun) - [kubernetes](./examples/typescript/kubernetes) +- [ucloud](./examples/typescript/ucloud) - [vault](./examples/typescript/vault) #### Backends @@ -69,6 +70,7 @@ Choose a language: - [azure](./examples/python/azure) - [docker](./examples/python/docker) - [kubernetes](./examples/python/kubernetes) +- [ucloud](./examples/python/ucloud) ### Java @@ -77,12 +79,14 @@ Choose a language: - [google](./examples/java/google) - [gradle-shared-module](./examples/java/gradle-shared-module) - [kubernetes](./examples/java/kubernetes) +- [ucloud](./examples/java/ucloud) ### C# - [aws](./examples/csharp/aws) - [azure](./examples/csharp/azure) - [google](./examples/csharp/google) +- [ucloud](./examples/csharp/ucloud) ### Go @@ -91,6 +95,7 @@ Choose a language: - [docker](./examples/go/docker) - [aws](./examples/go/aws) ⚠️ _High memory usage: the provider generation currently needs ~6 GB of memory. Hence the maximum for Node.js is [currently set to 8GB](https://github.com/hashicorp/terraform-cdk/blob/11d2e783d1fe94e50abd116ba73689c02590a391/packages/cdktf-cli/lib/get/constructs-maker.ts#L279)_ - [google cloud kubernetes engine + kubernetes](./examples/go/google) +- [ucloud](./examples/go/ucloud) ## Documentation diff --git a/examples/csharp/ucloud/.gitignore b/examples/csharp/ucloud/.gitignore new file mode 100644 index 0000000000..6fa757c339 --- /dev/null +++ b/examples/csharp/ucloud/.gitignore @@ -0,0 +1,343 @@ +# cdktf and terraform ignores +.terraform +cdktf.out +terraform.tfstate* + +# Created by https://www.gitignore.io/api/csharp + +### Csharp ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + + +# End of https://www.gitignore.io/api/csharp \ No newline at end of file diff --git a/examples/csharp/ucloud/Main.cs b/examples/csharp/ucloud/Main.cs new file mode 100644 index 0000000000..6af3a1e44e --- /dev/null +++ b/examples/csharp/ucloud/Main.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using ucloud; +using Constructs; +using HashiCorp.Cdktf; + + +namespace MyCompany.MyApp +{ + class MyApp : TerraformStack + { + public MyApp(Construct scope, string id) : base(scope, id) + { + new UcloudProvider(this, "ucloud", new UcloudProviderConfig { + Region = "cn-bj2", + ProjectId = System.Environment.GetEnvironmentVariable("UCLOUD_PROJECT_ID") ?? "", + }); + + DataUcloudImages images = new DataUcloudImages(this, "images", new DataUcloudImagesConfig { + AvailabilityZone = "cn-bj2-04", + NameRegex = "^CentOS 8.2 64", + ImageType = "base", + }); + + new Instance(this, "web", new InstanceConfig { + AvailabilityZone = "cn-bj2-04", + ImageId = images.Images("0").Id, + InstanceType = "n-basic-2", + RootPassword = "wA1234567", + Name = "cdktf-example-instance", + Tag = "tf-example", + BootDiskType = "cloud_ssd", + }); + } + + public static void Main(string[] args) + { + App app = new App(); + new MyApp(app, "ucloud"); + app.Synth(); + Console.WriteLine("App synth complete"); + } + } +} diff --git a/examples/csharp/ucloud/MyTerraformStack.csproj b/examples/csharp/ucloud/MyTerraformStack.csproj new file mode 100644 index 0000000000..1b3414b500 --- /dev/null +++ b/examples/csharp/ucloud/MyTerraformStack.csproj @@ -0,0 +1,16 @@ + + + + Exe + netcoreapp3.1 + + + + + + + + + + + diff --git a/examples/csharp/ucloud/NuGet.Config b/examples/csharp/ucloud/NuGet.Config new file mode 100644 index 0000000000..0fe86c2ea6 --- /dev/null +++ b/examples/csharp/ucloud/NuGet.Config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/examples/csharp/ucloud/cdktf.json b/examples/csharp/ucloud/cdktf.json new file mode 100644 index 0000000000..db16d4d04f --- /dev/null +++ b/examples/csharp/ucloud/cdktf.json @@ -0,0 +1,8 @@ +{ + "language": "csharp", + "app": "dotnet run -p MyTerraformStack.csproj", + "terraformProviders": ["ucloud/ucloud@~> 1.29.0"], + "context": { + "excludeStackIdFromLogicalIds": "true" + } +} diff --git a/examples/csharp/ucloud/help b/examples/csharp/ucloud/help new file mode 100644 index 0000000000..194568d13c --- /dev/null +++ b/examples/csharp/ucloud/help @@ -0,0 +1,22 @@ +======================================================================================================== + + Your cdktf csharp project is ready! + + cat help Prints this message + + Compile: + dotnet build Builds your dotnet packages + + Synthesize: + cdktf synth Synthesize Terraform resources to cdktf.out/ + + Diff: + cdktf diff Perform a diff (terraform plan) for the given stack + + Deploy: + cdktf deploy Deploy the given stack + + Destroy: + cdktf destroy Destroy the given stack + +======================================================================================================== \ No newline at end of file diff --git a/examples/csharp/ucloud/package.json b/examples/csharp/ucloud/package.json new file mode 100644 index 0000000000..faab78bf42 --- /dev/null +++ b/examples/csharp/ucloud/package.json @@ -0,0 +1,11 @@ +{ + "name": "@examples/csharp-ucloud", + "version": "0.0.0", + "license": "MPL-2.0", + "scripts": { + "//": "dotnet nuget locals -c all should be used if re-installing with the same version number", + "reinstall": "dotnet restore", + "build": "cdktf get", + "synth": "cdktf synth" + } +} diff --git a/examples/go/ucloud/.gitignore b/examples/go/ucloud/.gitignore new file mode 100644 index 0000000000..bf634dacc6 --- /dev/null +++ b/examples/go/ucloud/.gitignore @@ -0,0 +1,12 @@ +.terraform +cdktf.out +terraform.tfstate* +generated + +.idea +.settings +.vscode +*.iml + +# go build output +docker \ No newline at end of file diff --git a/examples/go/ucloud/cdktf.json b/examples/go/ucloud/cdktf.json new file mode 100644 index 0000000000..a79fa5fbb9 --- /dev/null +++ b/examples/go/ucloud/cdktf.json @@ -0,0 +1,9 @@ +{ + "language": "go", + "app": "go run main.go", + "codeMakerOutput": "generated", + "terraformProviders": [ + "ucloud/ucloud@~> 1.28.0" + ], + "terraformModules": [] +} diff --git a/examples/go/ucloud/go.mod b/examples/go/ucloud/go.mod new file mode 100644 index 0000000000..a04dafe53b --- /dev/null +++ b/examples/go/ucloud/go.mod @@ -0,0 +1,12 @@ +module github.com/hashicorp/terraform-cdk/examples/go/ucloud + +go 1.16 + +require ( + github.com/aws/constructs-go/constructs/v3 v3.3.75 + github.com/aws/jsii-runtime-go v1.30.0 + github.com/hashicorp/terraform-cdk-go/cdktf v0.0.0 +) + +// only required when running example against terraform-cdk repo locally +replace github.com/hashicorp/terraform-cdk-go/cdktf => ../../../packages/cdktf/dist/go/cdktf diff --git a/examples/go/ucloud/go.sum b/examples/go/ucloud/go.sum new file mode 100644 index 0000000000..993a8f8f2a --- /dev/null +++ b/examples/go/ucloud/go.sum @@ -0,0 +1,18 @@ +github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= +github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= +github.com/aws/constructs-go/constructs/v3 v3.3.75 h1:sunQ8/mQwVoV0OdGYmSh/s8Z2XyUXr8hCc/bKzz6SoU= +github.com/aws/constructs-go/constructs/v3 v3.3.75/go.mod h1:gh+X5UyxGPp/fWyp8iVMa75yMDQev4639pQ93HXXMoA= +github.com/aws/jsii-runtime-go v1.28.0/go.mod h1:6tZnlstx8bAB3vnLFF9n8bbkI//LDblAek9zFyMXV3E= +github.com/aws/jsii-runtime-go v1.29.0/go.mod h1:6tZnlstx8bAB3vnLFF9n8bbkI//LDblAek9zFyMXV3E= +github.com/aws/jsii-runtime-go v1.30.0 h1:KEQ0G78/VVmgRyXKwKdRTbJF2O9VVG39Hv1Y/iROGbo= +github.com/aws/jsii-runtime-go v1.30.0/go.mod h1:6tZnlstx8bAB3vnLFF9n8bbkI//LDblAek9zFyMXV3E= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/examples/go/ucloud/main.go b/examples/go/ucloud/main.go new file mode 100644 index 0000000000..ada12fed22 --- /dev/null +++ b/examples/go/ucloud/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "os" + + "github.com/aws/constructs-go/constructs/v3" + "github.com/aws/jsii-runtime-go" + "github.com/hashicorp/terraform-cdk-go/cdktf" + "github.com/hashicorp/terraform-cdk/examples/go/ucloud/generated/ucloud/ucloud" +) + +func NewMyStack(scope constructs.Construct, id string) cdktf.TerraformStack { + stack := cdktf.NewTerraformStack(scope, &id) + + ucloud.NewUcloudProvider(stack, jsii.String("ucloud"), &ucloud.UcloudProviderConfig{ + Region: jsii.String("cn-bj2"), + ProjectId: jsii.String(os.Getenv("UCLOUD_PROJECT_ID")), + }) + + images := ucloud.NewDataUcloudImages(stack, jsii.String("images"), &ucloud.DataUcloudImagesConfig{ + AvailabilityZone: jsii.String("cn-bj2-04"), + NameRegex: jsii.String("^CentOS 8.2 64"), + ImageType: jsii.String("base"), + }) + + ucloud.NewInstance(stack, jsii.String("web"), &ucloud.InstanceConfig{ + AvailabilityZone: jsii.String("cn-bj2-04"), + ImageId: images.Images(jsii.String("0")).Id(), + InstanceType: jsii.String("n-basic-2"), + RootPassword: jsii.String("wA1234567"), + Name: jsii.String("cdktf-example-instance"), + Tag: jsii.String("tf-example"), + BootDiskType: jsii.String("cloud_ssd"), + }) + return stack +} + +func main() { + app := cdktf.NewApp(nil) + + NewMyStack(app, "go-ucloud") + + app.Synth() +} diff --git a/examples/go/ucloud/package.json b/examples/go/ucloud/package.json new file mode 100644 index 0000000000..ce41965bec --- /dev/null +++ b/examples/go/ucloud/package.json @@ -0,0 +1,10 @@ +{ + "name": "@examples/go-ucloud", + "version": "0.0.0", + "license": "MPL-2.0", + "scripts": { + "reinstall": "rm go.sum", + "build": "cdktf get && go mod tidy", + "synth": "cdktf synth" + } + } diff --git a/examples/java/ucloud/.gitignore b/examples/java/ucloud/.gitignore new file mode 100644 index 0000000000..8d38fffab9 --- /dev/null +++ b/examples/java/ucloud/.gitignore @@ -0,0 +1,13 @@ +.terraform +cdktf.out +terraform.tfstate* +src/main/java/imports/ +src/main/resources/imports/ + +.classpath +.project +.idea +.settings +.vscode +*.iml +target/ \ No newline at end of file diff --git a/examples/java/ucloud/.mvn/jvm.config b/examples/java/ucloud/.mvn/jvm.config new file mode 100644 index 0000000000..cacbcb6f2c --- /dev/null +++ b/examples/java/ucloud/.mvn/jvm.config @@ -0,0 +1 @@ +-Xmx3G \ No newline at end of file diff --git a/examples/java/ucloud/cdktf.json b/examples/java/ucloud/cdktf.json new file mode 100644 index 0000000000..9352a6359a --- /dev/null +++ b/examples/java/ucloud/cdktf.json @@ -0,0 +1,5 @@ +{ + "language": "java", + "app": "mvn -e -q compile exec:java", + "terraformProviders": ["ucloud/ucloud@~> 1.29.0"] +} diff --git a/examples/java/ucloud/help b/examples/java/ucloud/help new file mode 100644 index 0000000000..178e8da47c --- /dev/null +++ b/examples/java/ucloud/help @@ -0,0 +1,22 @@ +======================================================================================================== + + Your cdktf Java project is ready! + + cat help Prints this message + + Compile: + mvn compile Compiles your Java packages + + Synthesize: + cdktf synth Synthesize Terraform resources to cdktf.out/ + + Diff: + cdktf diff Perform a diff (terraform plan) for the given stack + + Deploy: + cdktf deploy Deploy the given stack + + Destroy: + cdktf destroy Destroy the given stack + +======================================================================================================== \ No newline at end of file diff --git a/examples/java/ucloud/package.json b/examples/java/ucloud/package.json new file mode 100644 index 0000000000..7ce2ad4779 --- /dev/null +++ b/examples/java/ucloud/package.json @@ -0,0 +1,10 @@ +{ + "name": "@examples/java-ucloud", + "version": "0.0.0", + "license": "MPL-2.0", + "scripts": { + "reinstall": "mvn install:install-file -Dfile=./../../../dist/java/com/hashicorp/cdktf/0.0.0/cdktf-0.0.0.jar -DgroupId=com.hashicorp -DartifactId=cdktf -Dversion=0.0.0 -Dpackaging=jar", + "build": "cdktf get", + "synth": "cdktf synth" + } +} diff --git a/examples/java/ucloud/pom.xml b/examples/java/ucloud/pom.xml new file mode 100644 index 0000000000..ce3e83a3ed --- /dev/null +++ b/examples/java/ucloud/pom.xml @@ -0,0 +1,54 @@ + + 4.0.0 + + com.mycompany.app + ucloud + ucloud + 0.1 + + + 1.8 + 1.8 + UTF-8 + + + + + com.hashicorp + cdktf + 0.0.0 + + + software.constructs + constructs + 3.0.0 + + + + + src/main/java + src/test/java + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + com.mycompany.app.Main + + + + + diff --git a/examples/java/ucloud/src/main/java/com/mycompany/app/Main.java b/examples/java/ucloud/src/main/java/com/mycompany/app/Main.java new file mode 100644 index 0000000000..901ed9aead --- /dev/null +++ b/examples/java/ucloud/src/main/java/com/mycompany/app/Main.java @@ -0,0 +1,49 @@ +package com.mycompany.app; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import com.hashicorp.cdktf.App; +import com.hashicorp.cdktf.TerraformOutput; +import com.hashicorp.cdktf.TerraformStack; + +import imports.ucloud.UcloudProvider; +import imports.ucloud.DataUcloudImages; +import imports.ucloud.Instance; +import software.constructs.Construct; + +public class Main extends TerraformStack { + public Main(final Construct scope, final String id) { + super(scope, id); + + UcloudProvider.Builder.create(this, "ucloud") + .region("cn-bj2") + .projectId(System.getenv().getOrDefault("UCLOUD_PROJECT_ID", "")) + .build(); + + DataUcloudImages images = DataUcloudImages.Builder.create(this, "images") + .availabilityZone("cn-bj2-04") + .nameRegex("^CentOS 8.2 64") + .imageType("base") + .build(); + + Instance.Builder.create(this, "web") + .availabilityZone("cn-bj2-04") + .imageId(images.images("0").getId()) + .instanceType("n-basic-2") + .rootPassword("wA1234567") + .name("cdktf-example-instance") + .tag("tf-example") + .bootDiskType("cloud_ssd") + .build(); + } + + public static void main(String[] args) { + final App app = new App(); + new Main(app, "ucloud"); + app.synth(); + } +} diff --git a/examples/python/ucloud/.gitignore b/examples/python/ucloud/.gitignore new file mode 100644 index 0000000000..97a62936eb --- /dev/null +++ b/examples/python/ucloud/.gitignore @@ -0,0 +1,3 @@ +dist/ +imports/ +terraform.tfstate* \ No newline at end of file diff --git a/examples/python/ucloud/Pipfile b/examples/python/ucloud/Pipfile new file mode 100644 index 0000000000..61782f1abd --- /dev/null +++ b/examples/python/ucloud/Pipfile @@ -0,0 +1,10 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[requires] +python_version = "3.7" + +[packages] +cdktf = {path = "./../../../dist/python/cdktf-0.0.0-py3-none-any.whl"} diff --git a/examples/python/ucloud/Pipfile.lock b/examples/python/ucloud/Pipfile.lock new file mode 100644 index 0000000000..524628451a --- /dev/null +++ b/examples/python/ucloud/Pipfile.lock @@ -0,0 +1,91 @@ +{ + "_meta": { + "hash": { + "sha256": "4d795221fae1915a3c9346d1137bbd6adb709356a0278af165e98d47c32e6ded" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.7" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "attrs": { + "hashes": [ + "sha256:31b2eced602aa8423c2aea9c76a724617ed67cf9513173fd3a4f03e3a929c7e6", + "sha256:832aa3cde19744e49938b91fea06d69ecb9e649c93ba974535d08ad92164f700" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==20.3.0" + }, + "cattrs": { + "hashes": [ + "sha256:277d12740b45e46318b41c3b2e4a3bc067a7b9971cf61f0e96497598ad83f282", + "sha256:a6233d0ce33d48ac71ef818f8e0b9309a89496b359994c4dfe9ad211c1f6d0a3" + ], + "markers": "python_version >= '3.7'", + "version": "==1.5.0" + }, + "cdktf": { + "hashes": [ + "sha256:fee39b0a866ad27d99dee04708ae91a65d6b11f383c88e9a709e20af035c3bca" + ], + "path": "./../../../dist/python/cdktf-0.0.0-py3-none-any.whl", + "version": "==0.0.0" + }, + "constructs": { + "hashes": [ + "sha256:7c6b8ebbe17aae327e6773668692516ff7434e4286c46843099a4971c639d9d4", + "sha256:b39e6acbad4fbab9b12f1f4a03fb1ee8f097ce6587c7b8ce8ccae50ed0fd533b" + ], + "markers": "python_version >= '3.6'", + "version": "==3.3.87" + }, + "jsii": { + "hashes": [ + "sha256:4a2002b920e19df3c13119bc525979bfe1ae6a8c0ccf7617a5a966b1ccd66fd6", + "sha256:800042650b6436eb37b5ea905937f0c4cfc8863d439477a7b00d8d189b65c622" + ], + "markers": "python_version ~= '3.6'", + "version": "==1.30.0" + }, + "publication": { + "hashes": [ + "sha256:0248885351febc11d8a1098d5c8e3ab2dabcf3e8c0c96db1e17ecd12b53afbe6", + "sha256:68416a0de76dddcdd2930d1c8ef853a743cc96c82416c4e4d3b5d901c6276dc4" + ], + "version": "==0.0.3" + }, + "python-dateutil": { + "hashes": [ + "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c", + "sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'", + "version": "==2.8.1" + }, + "six": { + "hashes": [ + "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926", + "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'", + "version": "==1.16.0" + }, + "typing-extensions": { + "hashes": [ + "sha256:0ac0f89795dd19de6b97debb0c6af1c70987fd80a2d62d1958f7e56fcc31b497", + "sha256:50b6f157849174217d0656f99dc82fe932884fb250826c18350e159ec6cdf342", + "sha256:779383f6086d90c99ae41cf0ff39aac8a7937a9283ce0a414e5dd782f4c94a84" + ], + "version": "==3.10.0.0" + } + }, + "develop": {} +} diff --git a/examples/python/ucloud/README.md b/examples/python/ucloud/README.md new file mode 100644 index 0000000000..ffbd98a1f1 --- /dev/null +++ b/examples/python/ucloud/README.md @@ -0,0 +1,39 @@ +# python-ucloud + +A CDK for Terraform application in Python. + +## Usage + +Install Pipenv using Homebrew by running: + +```bash +$ brew install pipenv +``` + +You can install Pipenv by visiting the [website](https://pipenv.pypa.io/en/latest/). + +Install project dependencies + +```shell +pipenv install +``` + +Generate CDK for Terraform constructs for Terraform providers and modules used in the project. + +```bash +cdktf get +``` + +You can now edit the `main.py` file if you want to modify any code. + +```bash +cdktf synth +``` + +The above command will create a folder called `cdktf.out` that contains all Terraform JSON configuration that was generated. + +```bash +cdktf deploy +``` + +Deploy the stack! diff --git a/examples/python/ucloud/cdktf.json b/examples/python/ucloud/cdktf.json new file mode 100644 index 0000000000..cf92bb09b4 --- /dev/null +++ b/examples/python/ucloud/cdktf.json @@ -0,0 +1,6 @@ +{ + "language": "python", + "app": "pipenv run python main.py", + "terraformProviders": ["ucloud/ucloud@~> 1.29.0"], + "codeMakerOutput": "imports" +} diff --git a/examples/python/ucloud/help b/examples/python/ucloud/help new file mode 100644 index 0000000000..335a541811 --- /dev/null +++ b/examples/python/ucloud/help @@ -0,0 +1,12 @@ +======================================================================================================== + + Your cdktf Python project is ready! + + cat help Prints this message + cdktf synth Synthesize Terraform resources to cdktf.out/ + cdktf get Imports Terraform Provider Resources + + Deploy: + terraform apply ./cdktf.out + +======================================================================================================== \ No newline at end of file diff --git a/examples/python/ucloud/main.py b/examples/python/ucloud/main.py new file mode 100755 index 0000000000..f16fff6ae5 --- /dev/null +++ b/examples/python/ucloud/main.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +import os +from constructs import Construct +from cdktf import App, TerraformStack +from imports.ucloud import DataUcloudImages, Instance, UcloudProvider + + +class MyStack(TerraformStack): + def __init__(self, scope: Construct, ns: str): + super().__init__(scope, ns) + + UcloudProvider( + self, "UCloud", + region="cn-bj2", + project_id=os.getenv("UCLOUD_PROJECT_ID") or "", + ) + images = DataUcloudImages( + self, "images", + availability_zone="cn-bj2-04", + name_regex="^CentOS 8.2 64", + image_type="base", + ) + Instance( + self, "web", + availability_zone="cn-bj2-04", + image_id=images.images("0").id, + instance_type="n-basic-2", + root_password="wA1234567", + name="cdktf-example-instance", + tag="tf-example", + boot_disk_type="cloud_ssd", + ) + + +app = App() +MyStack(app, "python-ucloud") + +app.synth() diff --git a/examples/python/ucloud/package.json b/examples/python/ucloud/package.json new file mode 100644 index 0000000000..b442b3b112 --- /dev/null +++ b/examples/python/ucloud/package.json @@ -0,0 +1,10 @@ +{ + "name": "@examples/python-ucloud", + "version": "0.0.0", + "license": "MPL-2.0", + "scripts": { + "reinstall": "rm Pipfile.lock && PIPENV_IGNORE_VIRTUALENVS=1 pipenv install", + "build": "cdktf get", + "synth": "cdktf synth" + } +} diff --git a/examples/typescript/ucloud/.gitignore b/examples/typescript/ucloud/.gitignore new file mode 100755 index 0000000000..8c84c966d3 --- /dev/null +++ b/examples/typescript/ucloud/.gitignore @@ -0,0 +1,9 @@ +*.d.ts +*.js +node_modules +cdktf.out +terraform.tfstate* +.gen +.terraform +google.json +!tsconfig.json \ No newline at end of file diff --git a/examples/typescript/ucloud/Readme.md b/examples/typescript/ucloud/Readme.md new file mode 100755 index 0000000000..7651308ef5 --- /dev/null +++ b/examples/typescript/ucloud/Readme.md @@ -0,0 +1,31 @@ +# Example for UCloud based on Typescript + +This is based on the provided examples for other providers but adapted to UCloud + +## Usage + +Install project dependencies + +```shell +yarn install +``` + +Generate CDK for Terraform constructs for Terraform provides and modules used in the project. + +```bash +cdktf get +``` + +You can now edit the `main.ts` file if you want to modify any code. + +Generate Terraform configuration + +```bash +cdktf synth +``` + +The above command will create a folder called `cdktf.out` that contains all Terraform JSON configuration that was generated. + +See changes `cdktf diff` and deploy via `cdktf deploy`. + +When you're done run `cdktf destroy`. diff --git a/examples/typescript/ucloud/cdktf.json b/examples/typescript/ucloud/cdktf.json new file mode 100755 index 0000000000..ae23b2dcbf --- /dev/null +++ b/examples/typescript/ucloud/cdktf.json @@ -0,0 +1,7 @@ +{ + "language": "typescript", + "app": "npm run --silent compile && node main.js", + "terraformProviders": [ + "ucloud/ucloud@~> 1.29.0" + ] +} diff --git a/examples/typescript/ucloud/help b/examples/typescript/ucloud/help new file mode 100755 index 0000000000..9662c25dc4 --- /dev/null +++ b/examples/typescript/ucloud/help @@ -0,0 +1,30 @@ +======================================================================================================== + + Your cdktf typescript project is ready! + + cat help Print this message + + Compile: + npm run compile Compile typescript code to javascript (or "yarn watch") + npm run watch Watch for changes and compile typescript in the background + npm run build cdktf get and compile typescript + + Synthesize: + cdktf synth Synthesize Terraform resources from stacks to cdktf.out/ (ready for 'terraform apply') + + Diff: + cdktf diff Perform a diff (terraform plan) for the given stack + + Deploy: + cdktf deploy Deploy the given stack + + Destroy: + cdktf destroy Destroy the stack + + + Upgrades: + npm run get Import/update Terraform providers and modules (you should check-in this directory) + npm run upgrade Upgrade cdktf modules to latest version + npm run upgrade:next Upgrade cdktf modules to latest "@next" version (last commit) + +======================================================================================================== diff --git a/examples/typescript/ucloud/main.ts b/examples/typescript/ucloud/main.ts new file mode 100755 index 0000000000..a559a459a4 --- /dev/null +++ b/examples/typescript/ucloud/main.ts @@ -0,0 +1,38 @@ +import { Construct } from "constructs"; +import { App, TerraformStack } from "cdktf"; +import { + UcloudProvider, + Instance, + DataUcloudImages, +} from "./.gen/providers/ucloud"; + +class MyStack extends TerraformStack { + constructor(scope: Construct, name: string) { + super(scope, name); + + new UcloudProvider(this, "UCloud", { + region: "cn-bj2", + projectId: process.env.UCLOUD_PROJECT_ID || "", + }); + + let images = new DataUcloudImages(this, "images", { + availabilityZone: "cn-bj2-04", + nameRegex: "^CentOS 8.2 64", + imageType: "base", + }); + + new Instance(this, "web", { + availabilityZone: "cn-bj2-04", + imageId: images.images("0").id, + instanceType: "n-basic-2", + rootPassword: "wA1234567", + name: "cdktf-example-instance", + tag: "tf-example", + bootDiskType: "cloud_ssd", + }); + } +} + +const app = new App(); +new MyStack(app, "typescript-ucloud"); +app.synth(); diff --git a/examples/typescript/ucloud/package.json b/examples/typescript/ucloud/package.json new file mode 100755 index 0000000000..405a287781 --- /dev/null +++ b/examples/typescript/ucloud/package.json @@ -0,0 +1,30 @@ +{ + "name": "@examples/typescript-ucloud", + "version": "0.0.0", + "main": "main.js", + "types": "main.ts", + "license": "MPL-2.0", + "private": true, + "scripts": { + "get": "cdktf get", + "build": "yarn get && tsc", + "synth": "cdktf synth", + "compile": "tsc --pretty", + "watch": "tsc -w", + "test": "echo ok", + "upgrade": "npm i cdktf@latest cdktf-cli@latest", + "upgrade:next": "npm i cdktf@next cdktf-cli@next" + }, + "engines": { + "node": ">=10.12" + }, + "dependencies": { + "cdktf": "0.0.0", + "constructs": "^3.0.0" + }, + "devDependencies": { + "@types/node": "^14.0.26", + "cdktf-cli": "0.0.0", + "typescript": "^3.9.7" + } +} diff --git a/examples/typescript/ucloud/tsconfig.json b/examples/typescript/ucloud/tsconfig.json new file mode 100755 index 0000000000..c2650dbf07 --- /dev/null +++ b/examples/typescript/ucloud/tsconfig.json @@ -0,0 +1,33 @@ +{ + "compilerOptions": { + "alwaysStrict": true, + "charset": "utf8", + "declaration": true, + "experimentalDecorators": true, + "inlineSourceMap": true, + "inlineSources": true, + "lib": [ + "es2018" + ], + "module": "CommonJS", + "noEmitOnError": true, + "noFallthroughCasesInSwitch": true, + "noImplicitAny": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "resolveJsonModule": true, + "strict": true, + "strictNullChecks": true, + "strictPropertyInitialization": true, + "stripInternal": true, + "target": "ES2018" + }, + "include": [ + "**/*.ts" + ], + "exclude": [ + "node_modules" + ] +} \ No newline at end of file