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

[WIP] Add node.js module containing Terraform interpolation functions #268

Closed
wants to merge 4 commits into from
Closed
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
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,27 @@ TESTPARALLELISM = 10
build::
go build ${PROJECT}/pkg/tfgen
go build ${PROJECT}/pkg/tfbridge
cd sdk/nodejs && npm install && npm run build

lint::
golangci-lint run

test_fast::
$(GO_TEST_FAST) ${GOPKGS}
cd 

test_all::
$(GO_TEST) ${GOPKGS}
cd sdk/nodejs && npm run test

.PHONY: publish_packages
publish_packages::
$(call STEP_MESSAGE)
./scripts/publish_packages.sh

# The travis_* targets are entrypoints for CI.
.PHONY: travis_cron travis_push travis_pull_request travis_api
travis_cron: all
travis_push: all
travis_push: all publish_packages
travis_pull_request: all
travis_api: all
45 changes: 45 additions & 0 deletions scripts/publish_packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
# publish.sh builds and publishes a release.
set -o nounset -o errexit -o pipefail
ROOT=$(dirname $0)/..

echo "Publishing NPM packages to NPMjs.com:"

# For each package, first create the package.json to publish. This must be different than the one we use for
# development and testing the SDK, since we use symlinking for those workflows. Namely, we must promote the SDK
# dependencies from peerDependencies that are resolved via those links, to real installable dependencies.
publish() {
node $(dirname $0)/promote.js ${@:2} < \
${ROOT}/sdk/nodejs/$1/bin/package.json > \
${ROOT}/sdk/nodejs/$1/bin/package.json.publish
pushd ${ROOT}/sdk/nodejs/$1/bin
mv package.json package.json.dev
mv package.json.publish package.json

NPM_TAG="dev"

# We use the "features/" prefix on branches that we want to build and publish for doing
# cross repo work. But in this case, we don't want to publish over "dev", since the bits
# could be totally busted and the dev tag tracks master.
if [[ "${TRAVIS_BRANCH:-}" == features/* ]]; then
NPM_TAG=$(echo "${TRAVIS_BRANCH}" | sed -e 's|^features/|feature-|g')
fi

# If the package doesn't have a pre-release tag, use the tag of latest instead of
# dev. NPM uses this tag as the default version to add, so we want it to mean
# the newest released version.
if [[ $(jq -r .version < package.json) != *-* ]]; then
NPM_TAG="latest"
fi

# Now, perform the publish.
npm publish -tag ${NPM_TAG}
npm info 2>/dev/null

# And finally restore the original package.json.
mv package.json package.json.publish
mv package.json.dev package.json
popd
}

publish terraform
2 changes: 2 additions & 0 deletions sdk/nodejs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules/
/.idea/
9 changes: 9 additions & 0 deletions sdk/nodejs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Pulumi Interpolation Functions for Terraform Users

This package contains many of the built-in interpolation functions from
[Terraform][tf], implemented in Node.js to allow easy migration from Terraform
to [Pulumi][pulumi].


[tf]: https://terraform.io
[pulumi]: https://pulumi.io
173 changes: 173 additions & 0 deletions sdk/nodejs/lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/**
* abs returns the absolute value of a given number. See also the signum function.
*
* Examples:
* - `abs(1)` returns `1`
* - `abs(-1)` returns `1`
* - `abs(-3.14)` returns `3.14`
*
* @param input number for which to return the absolute value
*/
export declare function abs(input: number): number;
/**
* basename returns the last element of a path.
*
* @param path the full path
*/
export declare function basename(path: string): string;
/**
* base64decode decodes base64-encoded data and returns the utf-8-encoded string. An
* error is thrown if the argument is not valid base64 data.
*
* @param encoded valid base64-encoded string
*/
export declare function base64decode(encoded: string): string;
/**
* base64encode returns a base64-encoded version of the given string.
*
* @param unencoded the string to encode
*/
export declare function base64encode(unencoded: string): string;
/**
* base64gzip compresses the given string with gzip and then returns the resulting data as
* a base64-encoded string.
*
* @param unencoded the string to compress and encode
*/
export declare function base64gzip(unencoded: string): string;
export declare function base64sha256(input: string): string;
export declare function base64sha512(input: string): string;
/**
* bcrypt returns the Blowfish encrypted hash of the string at the given cost. A default
* cost of 10 will be used if not provided.
*
* @param password password to encrypt
* @param cost defaults to 10 if unset
*/
export declare function bcrypt(password: string, cost?: number): string;
/**
* ceil returns the smallest integer value greater than or equal to the argument.
*
* @param input number of which to find the ceiling
*/
export declare function ceil(input: number): number;
export declare function chomp(input: string): string;
/**
* chunklist returns a list items chunked by size. For example:
*
* - chunklist(["id1", "id2", "id3"], 1) returns [["id1"], ["id2"], ["id3"]]
* - chunklist(["id1", "id2", "id3"], 2) returns [["id1", "id2"], ["id3"]]
*
* @param input the list to chunk
* @param size the size of each chunk
*/
export declare function chunklist<T>(input: T[], size: number): T[][];
/**
* coalesce returns the first non-empty string from the given arguments, or an empty string if all
* of the arguments are undefined.
*
* @param first a potentially non-empty stringj
* @param others other potentially non-empty values
*/
export declare function coalesce(first: string | undefined, ...others: (string | undefined)[]): string;
/**
* coalescelist returns the first non-empty list from the given arguments, or an empty list if
* all of the arguments are undefined or empty lists.
*
* @param first a potentially non-empty array
* @param others other potentially non-empty arrays
*/
export declare function coalescelist<T>(first: T[] | undefined, ...others: (T[] | undefined)[]): T[];
/**
* compact removes empty string elements from a list. This can be useful in some cases,
* for example when passing joined lists as module variables or when parsing module outputs.
*
* @param input a string array from which to remove empty values
*/
export declare function compact(input: string[]): string[];
/**
* concat combines two or more lists into a single list.
*
* @param first the first list
* @param others other lists
*/
export declare function concat<T>(first: T[], ...others: T[][]): T[];
/**
* contains returns true if an array contains the given element and returns false otherwise
* @param haystack the array in which to search
* @param needle the element for which to search
*/
export declare function contains<T>(haystack: T[], needle: T): boolean;
export declare function dirname(path: string): string;
export declare function distinct(input: string[]): string[];
export declare function element(inputList: string[], elementIndex: number): string;
export declare function file(path: string): string;
export declare function floor(input: number): number;
/**
* format returns a string formatted using the given base string and arguments.
*
* *NOTE*: This is not a 1-1 map of the Terraform `format` function, since it uses the
* node.js `sprintf-js` library instead of the implementation of `fmt.Sprintf` in the Go
* standard library. However, it is reasonably close in semantic and will work for a
* large number of simple use cases.
*
* @param formatString a format string
* @param args the arguments to be applied to the format string
*/
export declare function format(formatString: string, ...args: any[]): string;
export declare function formatlist(formatString: string, ...args: any[][]): string[];
export declare function indent(indentSize: number, stringToIndent: string): string;
export declare function index<T>(haystack: T[], needle: T): number;
export declare function join(separator: string, ...strings: string[][]): string;
export declare function jsonencode(input: any): string;
export declare function keys(input: {
[k: string]: any;
}): string[];
export declare function length(input: string | any[] | {
[k: string]: any;
}): number;
export declare function list<T>(...elements: T[]): T[];
export declare function log(x: number, base: number): number;
export declare function lookup<T>(inputMap: {
[k: string]: T;
}, key: string, defaultValue?: T): T;
export declare function lower(input: string): string;
export declare function map(...keyValuePairs: any[]): {
[k: string]: any;
};
export declare function max(...numbers: number[]): number;
export declare function merge(...maps: {
[k: string]: any;
}[]): {
[k: string]: any;
};
export declare function min(...numbers: number[]): number;
export declare function md5(input: string): string;
export declare function pathexpand(path: string): string;
export declare function pow(base: number, exponent: number): number;
export declare function replace(input: string, toMatch: string | RegExp, replacement: string): string;
export declare function sha1(input: string): string;
export declare function sha256(input: string): string;
export declare function sha512(input: string): string;
export declare function signum(input: number): number;
export declare function slice(input: string[], start: number, end: number): string[];
export declare function sort(input: string[]): string[];
export declare function split(separator: string, input: string): string[];
export declare function substr(input: string, offset: number, len: number): string;
export declare function transpose(inputMap: {
[k: string]: string[];
}): {
[k: string]: string[];
};
export declare function timestamp(): string;
export declare function title(input: string): string;
export declare function trimspace(input: string): string;
export declare function upper(input: string): string;
export declare function uuid(): string;
export declare function urlencode(input: string): string;
export declare function values<T>(inputMap: {
[k: string]: T;
}): T[];
export declare function zipmap<T>(keyList: string[], valueList: T[]): {
[k: string]: T;
};
Loading