@pulumi/hcloud
Version:
A Pulumi package for creating and managing hcloud cloud resources.
188 lines • 7.32 kB
JavaScript
;
// *** WARNING: this file was generated by pulumi-language-nodejs. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FirewallAttachment = void 0;
const pulumi = __importStar(require("@pulumi/pulumi"));
const utilities = __importStar(require("./utilities"));
/**
* Attaches resource to a Hetzner Cloud Firewall.
*
* _Note_: only one `hcloud.FirewallAttachment` per Firewall is allowed.
* Any resources that should be attached to that Firewall need to be
* specified in that `hcloud.FirewallAttachment`.
*
* ## Example Usage
*
* ### Attach Servers
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as hcloud from "@pulumi/hcloud";
*
* const testServer = new hcloud.Server("test_server", {
* name: "test-server",
* serverType: "cx23",
* image: "ubuntu-24.04",
* });
* const basicFirewall = new hcloud.Firewall("basic_firewall", {name: "basic_firewall"});
* const fwRef = new hcloud.FirewallAttachment("fw_ref", {
* firewallId: basicFirewall.id.apply(x =>Number(x)),
* serverIds: [testServer.id.apply(x =>Number(x))],
* });
* ```
*
* ### Attach Label Selectors
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as hcloud from "@pulumi/hcloud";
*
* const testServer = new hcloud.Server("test_server", {
* name: "test-server",
* serverType: "cx23",
* image: "ubuntu-24.04",
* labels: {
* "firewall-attachment": "test-server",
* },
* });
* const basicFirewall = new hcloud.Firewall("basic_firewall", {name: "basic_firewall"});
* const fwRef = new hcloud.FirewallAttachment("fw_ref", {
* firewallId: basicFirewall.id.apply(x =>Number(x)),
* labelSelectors: ["firewall-attachment=test-server"],
* });
* ```
*
* ### Ensure a server is attached to a Firewall on first boot
*
* The `firewallIds` property of the `hcloud.Server` resource ensures that
* a server is attached to the specified Firewalls before its first boot.
* This is **not** the case when using the `hcloud.FirewallAttachment`
* resource to attach servers to a Firewall. In some scenarios this may
* pose a security risk.
*
* The following workaround ensures that a server is attached to a Firewall
* _before_ it first boots. However, the workaround requires two Firewalls.
* Additionally the server resource definition needs to ignore any remote
* changes to the `hcloud_server.firewall_ids` property. This is done using
* the `ignoreRemoteFirewallIds` property of `hcloud.Server`.
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as hcloud from "@pulumi/hcloud";
* import * as std from "@pulumi/std";
*
* const denyAll = new hcloud.Firewall("deny_all", {name: "deny_all"});
* const testServer = new hcloud.Server("test_server", {
* name: "test-server",
* serverType: "cx23",
* image: "ubuntu-24.04",
* ignoreRemoteFirewallIds: true,
* firewallIds: [denyAll.id.apply(x =>Number(x))],
* });
* const allowRules = new hcloud.Firewall("allow_rules", {
* name: "allow_rules",
* rules: [{
* direction: "in",
* protocol: "tcp",
* port: "22",
* sourceIps: [
* "0.0.0.0/0",
* "::/0",
* ],
* destinationIps: [std.format({
* input: "%s/32",
* args: [testServer.ipv4Address],
* }).then(invoke => invoke.result)],
* }],
* });
* const denyAllAtt = new hcloud.FirewallAttachment("deny_all_att", {
* firewallId: denyAll.id.apply(x =>Number(x)),
* serverIds: [testServer.id.apply(x =>Number(x))],
* });
* const allowRulesAtt = new hcloud.FirewallAttachment("allow_rules_att", {
* firewallId: allowRules.id.apply(x =>Number(x)),
* serverIds: [testServer.id.apply(x =>Number(x))],
* });
* ```
*
* ## Import
*
* Firewall Attachments can be imported using the `id` of the firewall:
*
* ```sh
* $ pulumi import hcloud:index/firewallAttachment:FirewallAttachment example "$FIREWALL_ID"
* ```
*/
class FirewallAttachment extends pulumi.CustomResource {
/**
* Get an existing FirewallAttachment resource's state with the given name, ID, and optional extra
* properties used to qualify the lookup.
*
* @param name The _unique_ name of the resulting resource.
* @param id The _unique_ provider ID of the resource to lookup.
* @param state Any extra arguments used during the lookup.
* @param opts Optional settings to control the behavior of the CustomResource.
*/
static get(name, id, state, opts) {
return new FirewallAttachment(name, state, { ...opts, id: id });
}
/** @internal */
static __pulumiType = 'hcloud:index/firewallAttachment:FirewallAttachment';
/**
* Returns true if the given object is an instance of FirewallAttachment. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
static isInstance(obj) {
if (obj === undefined || obj === null) {
return false;
}
return obj['__pulumiType'] === FirewallAttachment.__pulumiType;
}
constructor(name, argsOrState, opts) {
let resourceInputs = {};
opts = opts || {};
if (opts.id) {
const state = argsOrState;
resourceInputs["firewallId"] = state?.firewallId;
resourceInputs["labelSelectors"] = state?.labelSelectors;
resourceInputs["serverIds"] = state?.serverIds;
}
else {
const args = argsOrState;
if (args?.firewallId === undefined && !opts.urn) {
throw new Error("Missing required property 'firewallId'");
}
resourceInputs["firewallId"] = args?.firewallId;
resourceInputs["labelSelectors"] = args?.labelSelectors;
resourceInputs["serverIds"] = args?.serverIds;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
super(FirewallAttachment.__pulumiType, name, resourceInputs, opts);
}
}
exports.FirewallAttachment = FirewallAttachment;
//# sourceMappingURL=firewallAttachment.js.map