1. Packages
  2. Scaleway
  3. API Docs
  4. InstanceUserData
Scaleway v1.14.0 published on Thursday, Jun 6, 2024 by pulumiverse

scaleway.InstanceUserData

Explore with Pulumi AI

scaleway logo
Scaleway v1.14.0 published on Thursday, Jun 6, 2024 by pulumiverse

    Creates and manages Scaleway compute Instance User Data values.

    User data is a key value store API you can use to provide data from and to your server without authentication. It is the mechanism by which a user can pass information contained in a local file to an Instance at launch time.

    The typical use case is to pass something like a shell script or a configuration file as user data.

    For more information about user_data check our documentation guide here.

    About cloud-init documentation please check this link.

    Example Usage

    Basic

    import * as pulumi from "@pulumi/pulumi";
    import * as scaleway from "@pulumiverse/scaleway";
    
    const config = new pulumi.Config();
    const userData = config.getObject("userData") || {
        "cloud-init": `#cloud-config
    apt-update: true
    apt-upgrade: true
    `,
        foo: "bar",
    };
    const mainInstanceServer = new scaleway.InstanceServer("mainInstanceServer", {
        image: "ubuntu_focal",
        type: "DEV1-S",
    });
    // User data with a single value
    const mainInstanceUserData = new scaleway.InstanceUserData("mainInstanceUserData", {
        serverId: mainInstanceServer.id,
        key: "foo",
        value: "bar",
    });
    // User Data with many keys.
    const data: scaleway.InstanceUserData[] = [];
    for (const range = {value: 0}; range.value < userData; range.value++) {
        data.push(new scaleway.InstanceUserData(`data-${range.value}`, {
            serverId: mainInstanceServer.id,
            key: range.key,
            value: range.value,
        }));
    }
    
    import pulumi
    import pulumiverse_scaleway as scaleway
    
    config = pulumi.Config()
    user_data = config.get_object("userData")
    if user_data is None:
        user_data = {
            "cloud-init": """#cloud-config
    apt-update: true
    apt-upgrade: true
    """,
            "foo": "bar",
        }
    main_instance_server = scaleway.InstanceServer("mainInstanceServer",
        image="ubuntu_focal",
        type="DEV1-S")
    # User data with a single value
    main_instance_user_data = scaleway.InstanceUserData("mainInstanceUserData",
        server_id=main_instance_server.id,
        key="foo",
        value="bar")
    # User Data with many keys.
    data = []
    for range in [{"value": i} for i in range(0, user_data)]:
        data.append(scaleway.InstanceUserData(f"data-{range['value']}",
            server_id=main_instance_server.id,
            key=range["key"],
            value=range["value"]))
    
    package main
    
    import (
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
    	"github.com/pulumiverse/pulumi-scaleway/sdk/go/scaleway"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		cfg := config.New(ctx, "")
    		userData := map[string]interface{}{
    			"cloud-init": "#cloud-config\napt-update: true\napt-upgrade: true\n",
    			"foo":        "bar",
    		}
    		if param := cfg.GetObject("userData"); param != nil {
    			userData = param
    		}
    		mainInstanceServer, err := scaleway.NewInstanceServer(ctx, "mainInstanceServer", &scaleway.InstanceServerArgs{
    			Image: pulumi.String("ubuntu_focal"),
    			Type:  pulumi.String("DEV1-S"),
    		})
    		if err != nil {
    			return err
    		}
    		// User data with a single value
    		_, err = scaleway.NewInstanceUserData(ctx, "mainInstanceUserData", &scaleway.InstanceUserDataArgs{
    			ServerId: mainInstanceServer.ID(),
    			Key:      pulumi.String("foo"),
    			Value:    pulumi.String("bar"),
    		})
    		if err != nil {
    			return err
    		}
    		// User Data with many keys.
    		var data []*scaleway.InstanceUserData
    		for index := 0; index < userData; index++ {
    			key0 := index
    			val0 := index
    			__res, err := scaleway.NewInstanceUserData(ctx, fmt.Sprintf("data-%v", key0), &scaleway.InstanceUserDataArgs{
    				ServerId: mainInstanceServer.ID(),
    				Key:      pulumi.Any(key0),
    				Value:    pulumi.Any(val0),
    			})
    			if err != nil {
    				return err
    			}
    			data = append(data, __res)
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Scaleway = Pulumiverse.Scaleway;
    
    return await Deployment.RunAsync(() => 
    {
        var config = new Config();
        var userData = config.GetObject<dynamic>("userData") ?? 
        {
            { "cloud-init", @"#cloud-config
    apt-update: true
    apt-upgrade: true
    " },
            { "foo", "bar" },
        };
        var mainInstanceServer = new Scaleway.InstanceServer("mainInstanceServer", new()
        {
            Image = "ubuntu_focal",
            Type = "DEV1-S",
        });
    
        // User data with a single value
        var mainInstanceUserData = new Scaleway.InstanceUserData("mainInstanceUserData", new()
        {
            ServerId = mainInstanceServer.Id,
            Key = "foo",
            Value = "bar",
        });
    
        // User Data with many keys.
        var data = new List<Scaleway.InstanceUserData>();
        for (var rangeIndex = 0; rangeIndex < userData; rangeIndex++)
        {
            var range = new { Value = rangeIndex };
            data.Add(new Scaleway.InstanceUserData($"data-{range.Value}", new()
            {
                ServerId = mainInstanceServer.Id,
                Key = range.Key,
                Value = range.Value,
            }));
        }
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.scaleway.InstanceServer;
    import com.pulumi.scaleway.InstanceServerArgs;
    import com.pulumi.scaleway.InstanceUserData;
    import com.pulumi.scaleway.InstanceUserDataArgs;
    import com.pulumi.codegen.internal.KeyedValue;
    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) {
            final var config = ctx.config();
            final var userData = config.get("userData").orElse(%!v(PANIC=Format method: runtime error: invalid memory address or nil pointer dereference));
            var mainInstanceServer = new InstanceServer("mainInstanceServer", InstanceServerArgs.builder()        
                .image("ubuntu_focal")
                .type("DEV1-S")
                .build());
    
            // User data with a single value
            var mainInstanceUserData = new InstanceUserData("mainInstanceUserData", InstanceUserDataArgs.builder()        
                .serverId(mainInstanceServer.id())
                .key("foo")
                .value("bar")
                .build());
    
            // User Data with many keys.
            for (var i = 0; i < userData; i++) {
                new InstanceUserData("data-" + i, InstanceUserDataArgs.builder()            
                    .serverId(mainInstanceServer.id())
                    .key(range.key())
                    .value(range.value())
                    .build());
    
            
    }
        }
    }
    
    configuration:
      userData:
        type: dynamic
        default:
          cloud-init: |
            #cloud-config
            apt-update: true
            apt-upgrade: true        
          foo: bar
    resources:
      # User data with a single value
      mainInstanceUserData:
        type: scaleway:InstanceUserData
        properties:
          serverId: ${mainInstanceServer.id}
          key: foo
          value: bar
      # User Data with many keys.
      data:
        type: scaleway:InstanceUserData
        properties:
          serverId: ${mainInstanceServer.id}
          key: ${range.key}
          value: ${range.value}
        options: {}
      mainInstanceServer:
        type: scaleway:InstanceServer
        properties:
          image: ubuntu_focal
          type: DEV1-S
    

    Create InstanceUserData Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new InstanceUserData(name: string, args: InstanceUserDataArgs, opts?: CustomResourceOptions);
    @overload
    def InstanceUserData(resource_name: str,
                         args: InstanceUserDataArgs,
                         opts: Optional[ResourceOptions] = None)
    
    @overload
    def InstanceUserData(resource_name: str,
                         opts: Optional[ResourceOptions] = None,
                         key: Optional[str] = None,
                         server_id: Optional[str] = None,
                         value: Optional[str] = None,
                         zone: Optional[str] = None)
    func NewInstanceUserData(ctx *Context, name string, args InstanceUserDataArgs, opts ...ResourceOption) (*InstanceUserData, error)
    public InstanceUserData(string name, InstanceUserDataArgs args, CustomResourceOptions? opts = null)
    public InstanceUserData(String name, InstanceUserDataArgs args)
    public InstanceUserData(String name, InstanceUserDataArgs args, CustomResourceOptions options)
    
    type: scaleway:InstanceUserData
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args InstanceUserDataArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args InstanceUserDataArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args InstanceUserDataArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args InstanceUserDataArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args InstanceUserDataArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var instanceUserDataResource = new Scaleway.InstanceUserData("instanceUserDataResource", new()
    {
        Key = "string",
        ServerId = "string",
        Value = "string",
        Zone = "string",
    });
    
    example, err := scaleway.NewInstanceUserData(ctx, "instanceUserDataResource", &scaleway.InstanceUserDataArgs{
    	Key:      pulumi.String("string"),
    	ServerId: pulumi.String("string"),
    	Value:    pulumi.String("string"),
    	Zone:     pulumi.String("string"),
    })
    
    var instanceUserDataResource = new InstanceUserData("instanceUserDataResource", InstanceUserDataArgs.builder()
        .key("string")
        .serverId("string")
        .value("string")
        .zone("string")
        .build());
    
    instance_user_data_resource = scaleway.InstanceUserData("instanceUserDataResource",
        key="string",
        server_id="string",
        value="string",
        zone="string")
    
    const instanceUserDataResource = new scaleway.InstanceUserData("instanceUserDataResource", {
        key: "string",
        serverId: "string",
        value: "string",
        zone: "string",
    });
    
    type: scaleway:InstanceUserData
    properties:
        key: string
        serverId: string
        value: string
        zone: string
    

    InstanceUserData Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    The InstanceUserData resource accepts the following input properties:

    Key string
    Key of the user data.
    ServerId string
    The ID of the server associated with.
    Value string
    Value associated with your key
    Zone string

    zone) The zone in which the server should be created.

    Important: Use the cloud-init key to use cloud-init on your instance. You can define values using:

    • string
    • UTF-8 encoded file content using file
    Key string
    Key of the user data.
    ServerId string
    The ID of the server associated with.
    Value string
    Value associated with your key
    Zone string

    zone) The zone in which the server should be created.

    Important: Use the cloud-init key to use cloud-init on your instance. You can define values using:

    • string
    • UTF-8 encoded file content using file
    key String
    Key of the user data.
    serverId String
    The ID of the server associated with.
    value String
    Value associated with your key
    zone String

    zone) The zone in which the server should be created.

    Important: Use the cloud-init key to use cloud-init on your instance. You can define values using:

    • string
    • UTF-8 encoded file content using file
    key string
    Key of the user data.
    serverId string
    The ID of the server associated with.
    value string
    Value associated with your key
    zone string

    zone) The zone in which the server should be created.

    Important: Use the cloud-init key to use cloud-init on your instance. You can define values using:

    • string
    • UTF-8 encoded file content using file
    key str
    Key of the user data.
    server_id str
    The ID of the server associated with.
    value str
    Value associated with your key
    zone str

    zone) The zone in which the server should be created.

    Important: Use the cloud-init key to use cloud-init on your instance. You can define values using:

    • string
    • UTF-8 encoded file content using file
    key String
    Key of the user data.
    serverId String
    The ID of the server associated with.
    value String
    Value associated with your key
    zone String

    zone) The zone in which the server should be created.

    Important: Use the cloud-init key to use cloud-init on your instance. You can define values using:

    • string
    • UTF-8 encoded file content using file

    Outputs

    All input properties are implicitly available as output properties. Additionally, the InstanceUserData resource produces the following output properties:

    Id string
    The provider-assigned unique ID for this managed resource.
    Id string
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing InstanceUserData Resource

    Get an existing InstanceUserData resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: InstanceUserDataState, opts?: CustomResourceOptions): InstanceUserData
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            key: Optional[str] = None,
            server_id: Optional[str] = None,
            value: Optional[str] = None,
            zone: Optional[str] = None) -> InstanceUserData
    func GetInstanceUserData(ctx *Context, name string, id IDInput, state *InstanceUserDataState, opts ...ResourceOption) (*InstanceUserData, error)
    public static InstanceUserData Get(string name, Input<string> id, InstanceUserDataState? state, CustomResourceOptions? opts = null)
    public static InstanceUserData get(String name, Output<String> id, InstanceUserDataState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    Key string
    Key of the user data.
    ServerId string
    The ID of the server associated with.
    Value string
    Value associated with your key
    Zone string

    zone) The zone in which the server should be created.

    Important: Use the cloud-init key to use cloud-init on your instance. You can define values using:

    • string
    • UTF-8 encoded file content using file
    Key string
    Key of the user data.
    ServerId string
    The ID of the server associated with.
    Value string
    Value associated with your key
    Zone string

    zone) The zone in which the server should be created.

    Important: Use the cloud-init key to use cloud-init on your instance. You can define values using:

    • string
    • UTF-8 encoded file content using file
    key String
    Key of the user data.
    serverId String
    The ID of the server associated with.
    value String
    Value associated with your key
    zone String

    zone) The zone in which the server should be created.

    Important: Use the cloud-init key to use cloud-init on your instance. You can define values using:

    • string
    • UTF-8 encoded file content using file
    key string
    Key of the user data.
    serverId string
    The ID of the server associated with.
    value string
    Value associated with your key
    zone string

    zone) The zone in which the server should be created.

    Important: Use the cloud-init key to use cloud-init on your instance. You can define values using:

    • string
    • UTF-8 encoded file content using file
    key str
    Key of the user data.
    server_id str
    The ID of the server associated with.
    value str
    Value associated with your key
    zone str

    zone) The zone in which the server should be created.

    Important: Use the cloud-init key to use cloud-init on your instance. You can define values using:

    • string
    • UTF-8 encoded file content using file
    key String
    Key of the user data.
    serverId String
    The ID of the server associated with.
    value String
    Value associated with your key
    zone String

    zone) The zone in which the server should be created.

    Important: Use the cloud-init key to use cloud-init on your instance. You can define values using:

    • string
    • UTF-8 encoded file content using file

    Import

    User data can be imported using the {zone}/{key}/{server_id}, e.g.

    bash

    $ pulumi import scaleway:index/instanceUserData:InstanceUserData main fr-par-1/cloud-init/11111111-1111-1111-1111-111111111111
    

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    scaleway pulumiverse/pulumi-scaleway
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the scaleway Terraform Provider.
    scaleway logo
    Scaleway v1.14.0 published on Thursday, Jun 6, 2024 by pulumiverse