Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add installation file #426

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ci-mgmt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ env:
makeTemplate: bridged
team: ecosystem
pulumiConvert: 1
registryDocs: true
plugins:
- name: terraform
version: "1.0.16"
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ development: install_plugins provider build_sdks install_sdks

build: install_plugins provider build_sdks install_sdks

build_sdks: build_nodejs build_python build_dotnet build_go build_java
build_sdks: build_nodejs build_python build_dotnet build_go build_java build_registry_docs

install_go_sdk:

Expand Down Expand Up @@ -96,6 +96,10 @@ build_python: upstream
cd ./bin && \
../venv/bin/python -m build .

# Run the bridge's registry-docs command to generated the content of the installation docs/ folder at provider repo root
build_registry_docs:
$(WORKING_DIR)/bin/$(TFGEN) registry-docs --out $(WORKING_DIR)/docs

clean:
rm -rf sdk/{dotnet,nodejs,go,python}

Expand Down
203 changes: 203 additions & 0 deletions docs/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
---
title: Libvirt Provider
meta_desc: Provides an overview on how to configure the Pulumi Libvirt provider.
layout: package
---
## Installation

The libvirt provider is available as a package in all Pulumi languages:

* JavaScript/TypeScript: [`@pulumi/libvirt`](https://www.npmjs.com/package/@pulumi/libvirt)
* Python: [`pulumi-libvirt`](https://pypi.org/project/pulumi-libvirt/)
* Go: [`github.com/pulumi/pulumi-libvirt/sdk/go/libvirt`](https://github.com/pulumi/pulumi-libvirt)
* .NET: [`Pulumi.Libvirt`](https://www.nuget.org/packages/Pulumi.Libvirt)
* Java: [`com.pulumi/libvirt`](https://central.sonatype.com/artifact/com.pulumi/libvirt)
## Overview

The Libvirt provider is used to interact with Linux
[libvirt](https://libvirt.org) hypervisors.

The provider needs to be configured with the proper connection information
before it can be used.

> **Note:** while libvirt can be used with several types of hypervisors, this
provider focuses on [KVM](http://libvirt.org/drvqemu.html). Other drivers may not be
working and haven't been tested.
## The connection URI

The provider understands [connection URIs](https://libvirt.org/uri.html). The supported transports are:

* `tcp` (non-encrypted connection)
* `unix` (UNIX domain socket)
* `tls` (See [here](https://libvirt.org/kbase/tlscerts.html) for information how to setup certificates)
* `ssh` (Secure shell)

Unlike the original libvirt, the `ssh` transport is not implemented using the ssh command and therefore does not require `nc` (netcat) on the server side.

Additionally, the `ssh` URI supports passwords using the `driver+ssh://[username:PASSWORD@][hostname][:port]/[path]?sshauth=ssh-password` syntax.

As the provider does not use libvirt on the client side, not all connection URI options are supported or apply.
## Example Usage

{{< chooser language "typescript,python,go,csharp,java,yaml" >}}
{{% choosable language typescript %}}
```yaml
# Pulumi.yaml provider configuration file
name: configuration-example
runtime: nodejs
config:
libvirt:uri:
value: qemu:///system

```
```typescript
import * as pulumi from "@pulumi/pulumi";
import * as libvirt from "@pulumi/libvirt";

// Create a new domain
const test1 = new libvirt.Domain("test1", {});
```
{{% /choosable %}}
{{% choosable language python %}}
```yaml
# Pulumi.yaml provider configuration file
name: configuration-example
runtime: python
config:
libvirt:uri:
value: qemu:///system

```
```python
import pulumi
import pulumi_libvirt as libvirt

# Create a new domain
test1 = libvirt.Domain("test1")
```
{{% /choosable %}}
{{% choosable language csharp %}}
```yaml
# Pulumi.yaml provider configuration file
name: configuration-example
runtime: dotnet
config:
libvirt:uri:
value: qemu:///system

```
```csharp
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Libvirt = Pulumi.Libvirt;

return await Deployment.RunAsync(() =>
{
// Create a new domain
var test1 = new Libvirt.Domain("test1");

});

```
{{% /choosable %}}
{{% choosable language go %}}
```yaml
# Pulumi.yaml provider configuration file
name: configuration-example
runtime: go
config:
libvirt:uri:
value: qemu:///system

```
```go
package main

import (
"github.com/pulumi/pulumi-libvirt/sdk/go/libvirt"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
// Create a new domain
_, err := libvirt.NewDomain(ctx, "test1", nil)
if err != nil {
return err
}
return nil
})
}
```
{{% /choosable %}}
{{% choosable language yaml %}}
```yaml
# Pulumi.yaml provider configuration file
name: configuration-example
runtime: yaml
config:
libvirt:uri:
value: qemu:///system

```
```yaml
resources:
# Create a new domain
test1:
type: libvirt:Domain
```
{{% /choosable %}}
{{% choosable language java %}}
```yaml
# Pulumi.yaml provider configuration file
name: configuration-example
runtime: java
config:
libvirt:uri:
value: qemu:///system

```
```java
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.libvirt.Domain;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}

public static void stack(Context ctx) {
// Create a new domain
var test1 = new Domain("test1");

}
}
```
{{% /choosable %}}
{{< /chooser >}}
## Configuration Reference

The following keys can be used to configure the provider.

* `uri` - (Required) The [connection URI](https://libvirt.org/uri.html) used
to connect to the libvirt host.
## Environment variables

The libvirt connection URI can also be specified with the `LIBVIRT_DEFAULT_URI`
shell environment variable.

```
$ export LIBVIRT_DEFAULT_URI="qemu+ssh://[email protected]/system"
$ pulumi preview
```
44 changes: 36 additions & 8 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,42 @@ var metadata []byte
var networkModesRegexp = regexp.MustCompile("- `[a-z]*`: ")

func docRuleEdits(defaults []tfbridge.DocsEdit) []tfbridge.DocsEdit {
return append(defaults, tfbridge.DocsEdit{
Path: "network.markdown",
return append(
defaults,
tfbridge.DocsEdit{
Path: "network.markdown",
Edit: func(_ string, content []byte) ([]byte, error) {
return networkModesRegexp.ReplaceAllFunc(content,
func(src []byte) []byte {
return bytes.ReplaceAll(src,
[]byte("`"), []byte(`"`))
}), nil
},
},
fixUpInstallationFileExample,
fixupBadHclTag,
)
}

var fixUpInstallationFileExample = targetedReplace(
"index.html.markdown",
[]byte(`resource "libvirt_domain" "test1" {
...`),
[]byte(`resource "libvirt_domain" "test1" {
#...`),
)

var fixupBadHclTag = targetedReplace(
"index.html.markdown",
[]byte("shell environment variable.\n\n```hcl"),
[]byte("shell environment variable.\n\n```"),
)

func targetedReplace(filePath string, from, to []byte) tfbridge.DocsEdit {
return tfbridge.DocsEdit{
Path: filePath,
Edit: func(_ string, content []byte) ([]byte, error) {
return networkModesRegexp.ReplaceAllFunc(content,
func(src []byte) []byte {
return bytes.ReplaceAll(src,
[]byte("`"), []byte(`"`))
}), nil
return bytes.ReplaceAll(content, from, to), nil
},
})
}
}
Loading