Troubleshooting a Pulumi script in Azure using Typescript and encountering difficulties with function writing

My background is in using terraform, but now I am trying out Pulumi/typescript for the first time. In my codebase, I have two files - index.ts and blob.ts.

The create function in blob.ts is responsible for creating a storage account, resource group, blob container, and sending the storage account key to the monitor.

Unfortunately, I'm facing an issue with the last part of the blob.ts file. When I try to export the storageAccountKeys, I encounter an error saying "Modifiers cannot appear here.ts(1184)".

The goal is to keep only functions in the index.ts file, while storing all other code in separate *.ts files.

I would appreciate any guidance on where I might be making a mistake and if there's a different approach to accessing the storage account key for monitoring purposes.

//     blob.ts       //

import * as pulumi from "@pulumi/pulumi";
import * as resources from "@pulumi/azure-native/resources";
import * as storage from "@pulumi/azure-native/storage";

export default function CreateStorageContainer() {
    
    // Create an Azure Resource Group
    const resourceGroup = new resources.ResourceGroup("somegroup", {
        location: "westeurope",
        resourceGroupName: "somegroup",
    });

    // Create an Azure resource (Storage Account)
    const storageAccount = new storage.StorageAccount("sgsomestorageaccount", {
        accountName: "sgsomestorageaccount",
        resourceGroupName: resourceGroup.name,
        sku: {
            name: storage.SkuName.Standard_LRS,
        },
        kind: storage.Kind.StorageV2,
    });

    // Create Blob container with name : 
    const blobContainer = new storage.BlobContainer("someblobcontainer", {
        accountName: storageAccount.name,
        containerName: "someblobcontainer",
        resourceGroupName: resourceGroup.name,
    });

    // Export the primary key of the Storage Account
    export const storageAccountKeys = pulumi.all([resourceGroup.name, storageAccount.name]).apply(([resourceGroupName, accountName]) =>
        storage.listStorageAccountKeys({ resourceGroupName, accountName }));
    const primaryStorageKey = storageAccountKeys.keys[0].value;

}
//  index.ts  //
import CreateStorageContainer from "./blob.ts"
CreateStorageContainer();

Please see screenshot

Please see screenshot

Answer №1

In order to retrieve a value from a function, it must be returned instead of exported.

//     blob.ts       //

import * as pulumi from "@pulumi/pulumi";
import * as resources from "@pulumi/azure-native/resources";
import * as storage from "@pulumi/azure-native/storage";
import { ProximityPlacementGroupType } from "@pulumi/azure-native/compute/v20191201";

export default function CreateStorageContainer() {
  // Setting up an Azure Resource Group

  const resourceGroup = new resources.ResourceGroup("somegroup", {
    location: "westeurope",
    resourceGroupName: "somegroup",
  });

  // Creating an Azure resource (Storage Account)
  const storageAccount = new storage.StorageAccount("sgsomestorageaccount", {
    accountName: "sgsomestorageaccount",
    resourceGroupName: resourceGroup.name,
    sku: {
      name: storage.SkuName.Standard_LRS,
    },
    kind: storage.Kind.StorageV2,
  });

  // Establishing Blob container with specific name:
  const blobContainer = new storage.BlobContainer("someblobcontainer", {
    accountName: storageAccount.name,
    containerName: "someblobcontainer",
    resourceGroupName: resourceGroup.name,
  });

  // Retrieving the primary key of the Storage Account
  const storageAccountKeys = pulumi
    .all([resourceGroup.name, storageAccount.name])
    .apply(([resourceGroupName, accountName]) =>
      storage.listStorageAccountKeys({ resourceGroupName, accountName })
    );
  const primaryStorageKey = storageAccountKeys.keys[0].value;

  return [ storageAccountKeys, primaryStorageKey ] // make sure to provide desired values here

}

To export these values from Pulumi, the action needs to be done in your index.ts

import CreateStorageContainer from "./blob"

export const foo = CreateStorageContainer();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing the WebSocket readyState to showcase the connection status on the application header

I am currently in the process of developing a chat widget with svelte. I aim to indicate whether the websocket is connected or not by utilizing the websocket.readyState property, which has the following values: 0- Connecting, 1- Open, 2- Closing, 3- Close ...

NextJs Route Groups are causing issues as they do not properly exclude themselves from the app's layout.tsx

As far as I know, the layout.tsx in the app directory serves as the root layout. To customize the layout structure for specific segments, you can use Route Groups. More information can be found here. In this setup, any page.tsx file inside a directory nam ...

Experiencing CORS problem in Ionic 3 when accessing API on device

I am a newcomer to IONIC and I am utilizing a slim REST API with Ionic 3. Currently, I am encountering the following error: "Failed to load : Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin&apos ...

The functionality of the Request interface appears to be malfunctioning

Hey there, I'm currently working on building an API using Express and TypeScript. My goal is to extend the Request object to include a user property. I've done some research on Google and found several posts on StackOverflow that explain how to d ...

I am trying to figure out how to dynamically set the deployUrl during runtime in Angular

When working with Angular, the definition of "webpack_public_path" or "webpack_require.p" for a project can be done in multiple ways: By setting the deployUrl in the .angular-cli.json file By adding --deployUrl "some/path" to the "ng build" command line ...

Issue with MUI icon import: React, Typescript, and MUI type error - Overload does not match this call

Within my component, I am importing the following: import LogoutIcon from "@mui/icons-material/Logout"; import useLogout from "@/hooks/auth/useLogout"; const { trigger: logoutTrigger } = useLogout(); However, when utilizing this compo ...

unable to reinstall due to removal of global typing

After globally installing Moment typing with the command typings install dt~moment --save --global Checking the installed typings using typings list shows: ├── <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="93fffcf7f2e0 ...

Check the type of the indexed value

I need help with a standard interface: interface IProps<T> { item: T; key: keyof T; } Is there a way to guarantee that item[key] is either a string or number so it can be used as an index for Record<string | number, string>? My codeba ...

Custom protocol gateway for TCP connections in Azure IoT Hub

Having recently started working with Azure IoT Hub, I've noticed that our devices do not support MQTT and instead send telemetry using simple TCP. I've come across discussions about custom TCP implementations for the gateway where we can adjust t ...

The 'get' property in the class 'ToastInjector' cannot be assigned to the 'get' property in its base class 'Injector'

error TS2416: The property 'get' in the type 'ToastInjector' cannot be assigned to the same property in the base type 'Injector'. The type '(token: any, notFoundValue?: T, flags?: InjectFlags) => ToastPackage | T&apos ...

Can you achieve a union of strings and a single string?

Is there a way to create a type in TypeScript that can accept specific strings as well as any other string? type AcceptsWithString = | 'optionA' | 'optionB' | 'optionC' | string playground The goal here is to design a ty ...

The Ion-item-option button requires two clicks to activate

Within my ion-list, I have sliding items that are dynamically created using a for loop. Interestingly, when clicking on an item to navigate to another page, everything works fine. However, upon sliding an item, a button is revealed but it requires two clic ...

Remove the ability to select from the dropped list item

Here is the HTML and Javascript code I used to enable drag and drop functionality for list items from one div to another: HTML: <div class="listArea"> <h4> Drag and Drop list in Green Area: </h4> <ul class="unstyle"> & ...

ng-click-outside event triggers when clicking outside, including within child elements

I am looking to trigger a specific action when I click outside of the container. To achieve this, I have utilized the ng-click-outside directive which works well in most cases. However, there is one scenario where an issue arises. Inside the container, the ...

Ionic - Deleting an item from local storage

Currently, I am implementing local storage for my Ionic application. While I can successfully add and retrieve data from local storage, I encounter an issue when trying to delete a specific object - it ends up removing everything in the database. Moreover, ...

Unexpected Data Displayed by Material UI Modal Component

I'm currently facing an issue with my Material UI Modal component in a React/Typescript project. When a card element is clicked on the site, it should display expanded information in a modal view. However, clicking on any card only shows the most rece ...

Angular Typescript filter function returning an empty arrayIn an Angular project, a

I have a filtering function in Angular that is returning an empty array. Despite trying similar solutions from previous questions, the issue persists. The function itself appears to be correct. Any assistance would be greatly appreciated. gifts represents ...

Converting a JSON array into a TypeScript array

Looking to convert a JSON array into a TypeScript variable array. The JSON data retrieved from http://www.example.com/select.php: { "User":[ {"Name":"Luca M","ID":"1"}, {"Name":"Tim S","ID":"2"}, {"Name":"Lucas W","ID":"3"} ...

Angular 2 Issue: Error Message "Cannot bind to 'ngModel'" arises after FormsModule is added to app.module

I've been struggling with the data binding aspect of this tutorial for over a day now. Here's the link to the tutorial: https://angular.io/docs/ts/latest/tutorial/toh-pt1.html The error I keep encountering is: Unhandled Promise rejection: Tem ...

Combining 2 lists in Angular Firebase: A Simple Guide

I have been searching for a solution for the past 2 hours, but unfortunately haven't found one yet. Although I have experience working with both SQL and NoSQL databases, this particular issue is new to me. My problem is quite straightforward: I have t ...