Git Product home page Git Product logo

pulumi-dotnet's Introduction

.NET Language Provider

A .NET language provider for Pulumi. Use your favorite .NET language to write Pulumi programs and deploy infrastructure to any cloud.

Installing the nuget package

dotnet add package Pulumi

Example Pulumi program with .NET and C#

Here's a simple example of a Pulumi app written in C# that creates some simple AWS resources:

using System.Collections.Generic;
using System.Threading.Tasks;
using Pulumi;
using Pulumi.Aws.S3;

return await Deployment.RunAsync(() =>
{
    // Create the bucket, and make it public.
    var bucket = new Bucket("media", new () 
    { 
        Acl = "public-read" 
    });

    // Add some content.
    var content = new BucketObject("basic-content", new ()
    {
        Acl = "public-read",
        Bucket = bucket.Id,
        ContentType = "text/plain; charset=utf8",
        Key = "hello.txt",
        Source = new StringAsset("Made with ❤, Pulumi, and .NET"),
    });

    // Return some values that will become the Outputs of the stack.
    return new Dictionary<string, object>
    {
        ["hello"] = "world",
        ["bucket-id"] = bucket.Id,
        ["content-id"] = content.Id,
        ["object-url"] = Output.Format($"http://{bucket.BucketDomainName}/{content.Key}"),
    };
});

Make a Pulumi.yaml file:

$ cat Pulumi.yaml

name: hello-dotnet
runtime: dotnet

Then, configure it:

$ pulumi stack init hello-dotnet
$ pulumi config set aws:region us-west-2

And finally, pulumi preview and pulumi up as you would any other Pulumi project.

Development and Testing

Prerequisites

  • Dotnet SDK v6+ installed on your machine.
  • Go 1.19+ for building and testing pulumi-language-dotnet
  • The Pulumi CLI (used in automation tests and for integration tests)

Then you can run one of the following commands:

# Build the Pulumi SDK
dotnet run build-sdk

# Running tests for the Pulumi SDK
dotnet run test-sdk

# Running tests for the Pulumi Automation SDK
dotnet run test-automation-sdk

# Building the language plugin. A binary will be built into the pulumi-language-dotnet folder.
# this is the binary that will be used by the integration tests.
dotnet run build-language-plugin

# Testing the language plugin
dotnet run test-language-plugin

# Sync proto files from pulumi/pulumi
dotnet run sync-proto-files

# List all integration tests
dotnet run list-integration-tests

# Run a specific integration test
dotnet run integration test <testName>

# Run all integration tests
dotnet run all-integration-tests

Running integration tests

When running integration tests via an IDE like Goland or VSCode, you want the Pulumi CLI to use the pulumi-language-dotnet plugin from this repository, not the one that comes bundled with your Pulumi CLI. To do this, in your terminal dotnet run build-language-plugin or simply cd pulumi-language-dotnet && go build.

Alternatively, you can run dotnet run integration test <testName> or dotnet run all-integration-tests which will build the language plugin for you just before running the tests.

Public API Changes

When making changes to the code you may get the following compilation error:

error RS0016: Symbol XYZ' is not part of the declared API.

This indicates a change in public API. If you are developing a change and this is intentional, add the new API elements to PublicAPI.Shipped.txt corresponding to your project (some IDEs will do this automatically for you, but manual additions are fine as well).

pulumi-dotnet's People

Contributors

zaid-ajaj avatar frassle avatar mikhailshilkov avatar t0yv0 avatar justinvp avatar stack72 avatar komalali avatar cyrusnajmabadi avatar aaronfriel avatar bors[bot] avatar iwahbe avatar gitfool avatar orionstudt avatar pgavlin avatar vipentti avatar evanboyle avatar abhinav avatar lblackstone avatar jaxxstorm avatar lukehoban avatar mastoj avatar same-id avatar ffmathy avatar asjdf avatar jetvova avatar aq17 avatar yreynhout avatar unosd avatar nicro950 avatar nathanwinder-perficient avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.