import * as pulumi from "@pulumi/pulumi"; /** * Defines content that represents blocks of VCL logic that is inserted into your service. This resource will populate the content of a dynamic snippet and allow it to be manged without the creation of a new service verison. * * > **Note:** By default the Terraform provider allows you to externally manage the snippets via API or UI. * If you wish to apply your changes in the HCL, then you should explicitly set the `manageSnippets` attribute. An example of this configuration is provided below. * * ## Example Usage * * ### Terraform >= 0.12.6) * * Basic usage: * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as fastly from "@pulumi/fastly"; * * const myservice = new fastly.ServiceVcl("myservice", { * name: "snippet_test", * domains: [{ * name: "snippet.fastlytestdomain.com", * comment: "snippet test", * }], * backends: [{ * address: "http-me.fastly.dev", * name: "Glitch Test Site", * port: 80, * }], * dynamicsnippets: [{ * name: "My Dynamic Snippet", * type: "recv", * priority: 110, * }], * defaultHost: "http-me.fastly.dev", * forceDestroy: true, * }); * const myDynContent: fastly.ServiceDynamicSnippetContent[] = []; * myservice.dynamicsnippets.apply(dynamicsnippets => { * const myDynContent: fastly.ServiceDynamicSnippetContent[] = []; * pulumi.all(.filter(d => d.name == "My Dynamic Snippet").reduce((__obj, d) => ({ ...__obj, [d.name]: d }), {})).apply(rangeBody => { * for (const range of Object.entries(rangeBody).sort().map(([k, v]) => ({key: k, value: v}))) { * myDynContent.push(new fastly.ServiceDynamicSnippetContent(`my_dyn_content-${range.key}`, { * serviceId: myservice.id, * snippetId: range.value.snippetId, * content: `if ( req.url ) { * set req.http.my-snippet-test-header = "true"; * }`, * })); * } * }); * }); * ``` * * Multiple dynamic snippets: * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as fastly from "@pulumi/fastly"; * * const myservice = new fastly.ServiceVcl("myservice", { * name: "snippet_test", * domains: [{ * name: "snippet.fastlytestdomain.com", * comment: "snippet test", * }], * backends: [{ * address: "http-me.fastly.dev", * name: "Glitch Test Site", * port: 80, * }], * dynamicsnippets: [ * { * name: "My Dynamic Snippet One", * type: "recv", * priority: 110, * }, * { * name: "My Dynamic Snippet Two", * type: "recv", * priority: 110, * }, * ], * defaultHost: "http-me.fastly.dev", * forceDestroy: true, * }); * const myDynContentOne: fastly.ServiceDynamicSnippetContent[] = []; * myservice.dynamicsnippets.apply(dynamicsnippets => { * const myDynContentOne: fastly.ServiceDynamicSnippetContent[] = []; * pulumi.all(.filter(d => d.name == "My Dynamic Snippet One").reduce((__obj, d) => ({ ...__obj, [d.name]: d }), {})).apply(rangeBody => { * for (const range of Object.entries(rangeBody).sort().map(([k, v]) => ({key: k, value: v}))) { * myDynContentOne.push(new fastly.ServiceDynamicSnippetContent(`my_dyn_content_one-${range.key}`, { * serviceId: myservice.id, * snippetId: range.value.snippetId, * content: `if ( req.url ) { * set req.http.my-snippet-test-header-one = "true"; * }`, * })); * } * }); * }); * const myDynContentTwo: fastly.ServiceDynamicSnippetContent[] = []; * myservice.dynamicsnippets.apply(dynamicsnippets => { * const myDynContentTwo: fastly.ServiceDynamicSnippetContent[] = []; * pulumi.all(.filter(d => d.name == "My Dynamic Snippet Two").reduce((__obj, d) => ({ ...__obj, [d.name]: d }), {})).apply(rangeBody => { * for (const range of Object.entries(rangeBody).sort().map(([k, v]) => ({key: k, value: v}))) { * myDynContentTwo.push(new fastly.ServiceDynamicSnippetContent(`my_dyn_content_two-${range.key}`, { * serviceId: myservice.id, * snippetId: range.value.snippetId, * content: `if ( req.url ) { * set req.http.my-snippet-test-header-two = "true"; * }`, * })); * } * }); * }); * ``` * * ### Terraform >= 0.12.0 && < 0.12.6) * * `forEach` attributes were not available in Terraform before 0.12.6, however, users can still use `for` expressions to achieve * similar behaviour as seen in the example below. * * > **Warning:** Terraform might not properly calculate implicit dependencies on computed attributes when using `for` expressions * * For scenarios such as adding a Dynamic Snippet to a service and at the same time, creating the Dynamic Snippets (`fastly.ServiceDynamicSnippetContent`) * resource, Terraform will not calculate implicit dependencies correctly on `for` expressions. This will result in index lookup * problems and the execution will fail. * * For those scenarios, it's recommended to split the changes into two distinct steps: * * 1. Add the `dynamicsnippet` block to the `fastly.ServiceVcl` and apply the changes * 2. Add the `fastly.ServiceDynamicSnippetContent` resource with the `for` expressions to the HCL and apply the changes * * Usage: * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as fastly from "@pulumi/fastly"; * * const myservice = new fastly.ServiceVcl("myservice", { * name: "demofastly", * domains: [{ * name: "demo.notexample.com", * comment: "demo", * }], * dynamicsnippets: [{ * name: "My Dynamic Snippet", * type: "recv", * priority: 110, * }], * }); * const myDynContent = new fastly.ServiceDynamicSnippetContent("my_dyn_content", { * serviceId: myservice.id, * snippetId: myservice.dynamicsnippets.apply(dynamicsnippets => .reduce((__obj, s) => ({ ...__obj, [s.name]: s.snippetId }), {})["My Dynamic Snippet"]), * content: `if ( req.url ) { * set req.http.my-snippet-test-header = "true"; * }`, * }); * ``` * * ### Reapplying original snippets with `manageSnippets` if the state of the snippets drifts * * By default the user is opted out from reapplying the original changes if the snippets are managed externally. * The following example demonstrates how the `manageSnippets` field can be used to reapply the changes defined in the HCL if the state of the snippets drifts. * When the value is explicitly set to 'true', Terraform will keep the original changes and discard any other changes made under this resource outside of Terraform. * * > **Warning:** You will lose externally managed snippets if `manage_snippets=true`. * * > **Note:** The `ignoreChanges` built-in meta-argument takes precedence over `manageSnippets` regardless of its value. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as fastly from "@pulumi/fastly"; * * //... * const myDynContent: fastly.ServiceDynamicSnippetContent[] = []; * for (const range of Object.entries(.filter(d => d.name == "My Dynamic Snippet").reduce((__obj, d) => ({ ...__obj, [d.name]: d }), {})).sort().map(([k, v]) => ({key: k, value: v}))) { * myDynContent.push(new fastly.ServiceDynamicSnippetContent(`my_dyn_content-${range.key}`, { * serviceId: myservice.id, * snippetId: range.value.snippetId, * manageSnippets: true, * content: `if ( req.url ) { * set req.http.my-snippet-test-header = "true"; * }`, * })); * } * ``` * * ## Import * * This is an example of the import command being applied to the resource named `fastly_service_dynamic_snippet_content.content` * The resource ID is a combined value of the `serviceId` and `snippetId` separated by a forward slash. * * ```sh * $ pulumi import fastly:index/serviceDynamicSnippetContent:ServiceDynamicSnippetContent content xxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxx * ``` * * If Terraform is already managing remote content against a resource being imported then the user will be asked to remove it from the existing Terraform state. * The following is an example of the Terraform state command to remove the resource named `fastly_service_dynamic_snippet_content.content` from the Terraform state file. * * ```sh * $ terraform state rm fastly_service_dynamic_snippet_content.content * ``` */ export declare class ServiceDynamicSnippetContent extends pulumi.CustomResource { /** * Get an existing ServiceDynamicSnippetContent 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: string, id: pulumi.Input, state?: ServiceDynamicSnippetContentState, opts?: pulumi.CustomResourceOptions): ServiceDynamicSnippetContent; /** * Returns true if the given object is an instance of ServiceDynamicSnippetContent. This is designed to work even * when multiple copies of the Pulumi SDK have been loaded into the same process. */ static isInstance(obj: any): obj is ServiceDynamicSnippetContent; /** * The VCL code that specifies exactly what the snippet does */ readonly content: pulumi.Output; /** * Whether to reapply changes if the state of the snippets drifts, i.e. if snippets are managed externally */ readonly manageSnippets: pulumi.Output; /** * The ID of the service that the dynamic snippet belongs to */ readonly serviceId: pulumi.Output; /** * The ID of the dynamic snippet that the content belong to */ readonly snippetId: pulumi.Output; /** * Create a ServiceDynamicSnippetContent resource with the given unique name, arguments, and options. * * @param name The _unique_ name of the resource. * @param args The arguments to use to populate this resource's properties. * @param opts A bag of options that control this resource's behavior. */ constructor(name: string, args: ServiceDynamicSnippetContentArgs, opts?: pulumi.CustomResourceOptions); } /** * Input properties used for looking up and filtering ServiceDynamicSnippetContent resources. */ export interface ServiceDynamicSnippetContentState { /** * The VCL code that specifies exactly what the snippet does */ content?: pulumi.Input; /** * Whether to reapply changes if the state of the snippets drifts, i.e. if snippets are managed externally */ manageSnippets?: pulumi.Input; /** * The ID of the service that the dynamic snippet belongs to */ serviceId?: pulumi.Input; /** * The ID of the dynamic snippet that the content belong to */ snippetId?: pulumi.Input; } /** * The set of arguments for constructing a ServiceDynamicSnippetContent resource. */ export interface ServiceDynamicSnippetContentArgs { /** * The VCL code that specifies exactly what the snippet does */ content: pulumi.Input; /** * Whether to reapply changes if the state of the snippets drifts, i.e. if snippets are managed externally */ manageSnippets?: pulumi.Input; /** * The ID of the service that the dynamic snippet belongs to */ serviceId: pulumi.Input; /** * The ID of the dynamic snippet that the content belong to */ snippetId: pulumi.Input; } //# sourceMappingURL=serviceDynamicSnippetContent.d.ts.map