Creating a VPC resource in Pulumi to assign to an EC2 instance

Hey there! I'm having some trouble creating an ec2 instance with the vpc attached to it. Any help would be appreciated!

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const myVpc = new aws.ec2.Vpc("myVpc", {
  cidrBlock: "172.16.0.0/16",
  tags: {
    Name: "Darshan",
  },
});

const mySubnet = new aws.ec2.Subnet("mySubnet", {
  vpcId: myVpc.id,
  cidrBlock: "172.16.10.0/24",
  availabilityZone: "us-west-2a",
  tags: {
    Name: "Darshan",  
    },
});

const NetworkInterface = new aws.ec2.NetworkInterface("NetworkInterface", {
    subnetId: mySubnet.id,
    privateIps: ["172.16.10.100"],
    tags: {
        Name: "primary_network_interface",
    },
});

const Instance = new aws.ec2.Instance("Instance", {
    ami: "ami-020ae06fdda6a0f66",
    instanceType: "t2.micro",
    networkInterfaces: [{
        networkInterfaceId: NetworkInterface.id,
        deviceIndex: 0,
    }],
    creditSpecification: {
        cpuCredits: "unlimited",
    },
});

Answer №1

If you're looking to launch it, here are a few steps you can take:

#1. Opt for a t3.micro over a t2.micro as t3 instances are more cost-effective, offer greater memory and CPU capacity, and higher network bandwidth. You can compare the differences here: . This means you can eliminate the need for creditSpecification

#2. The AMI with ID ami-020ae06fdda6a0f66 is only available in us-east-2 (Ohio). This particular AMI, named

aws-elasticbeanstalk-amzn-2018.03.0.x86_64-tomcat8.5java8-hvm-201906160916
, appears to be referenced in the following AWS documentation, specifically launching it in us-east-2(Ohio). Therefore, switch to that region to proceed with the launch. If not, select an alternative AMI available in us-west-2.

#3. The provided code snippet functions correctly in us-east-2 with the previously mentioned AMI.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const myVpc = new aws.ec2.Vpc("demo-myVpc", {
    cidrBlock: "172.16.0.0/16",
    tags: {
      Name: "Darshan",
    },
  });

  const mySubnet = new aws.ec2.Subnet("demo-mySubnet", {
    vpcId: myVpc.id,
    cidrBlock: "172.16.10.0/24",
    availabilityZone: "us-east-2a",
    tags: {
      Name: "Darshan",  
      },
  });

  const Instance = new aws.ec2.Instance("demo-Instance", {
    ami: "ami-020ae06fdda6a0f66",
    instanceType: "t3.micro",
    subnetId: mySubnet.id,
  });

  export const my_vpc = myVpc.id;
  export const my_vpc_cidr_block = myVpc.cidrBlock;
  export const my_vpc_cidr_tags = myVpc.tags;
  export const my_subnet = mySubnet.id;
  export const my_subnet_cidr_block = mySubnet.cidrBlock;
  export const my_subnet_tags = mySubnet.tags;
  export const my_instance_ami = Instance.ami;
  export const my_instance_id = Instance.id;

To access the outputs, run: pulumi stack output

Current stack outputs (8):
    OUTPUT                VALUE
    my_instance_ami       ami-020ae06fdda6a0f66
    my_instance_id        i-02310475c052c8097
    my_subnet             subnet-0e8141c37b149ea77
    my_subnet_cidr_block  172.16.10.0/24
    my_subnet_tags        {"Name":"Darshan"}
    my_vpc                vpc-00eab339e95459c27
    my_vpc_cidr_block     172.16.0.0/16
    my_vpc_cidr_tags      {"Name":"Darshan"}

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

Angular 2: Issue with data table not updating after item deletion

I need assistance with updating a data table after deleting an item. The database is updated correctly when I delete an item, but the table does not automatically refresh to reflect the changes. managenews.component.ts import { Component, OnInit } from ...

What advantages does the Step function (AWS) offer compared to setTimeout (Javascript) for scheduling tasks?

I am currently in the process of developing an API service that allows any client to provide me with their HTTP request along with the desired time in seconds for execution. I have considered two potential approaches to achieve this: Utilizing a lambda f ...

Steps to disable TypeScript error messages for unused variables

I encountered an issue in my Angular CLI that says: jest.config.js is part of the TypeScript compilation but it's unused. Add only entry points to the 'files' or 'include' properties in your tsconfig. Additionally, I have a few o ...

Accessing the value of a FormControl in HTML代码

Modifying the value of a form select element programmatically presents an issue. Even after changing the value in the form, the paragraph element "p" remains hidden. However, if you manually adjust the form's value, the visibility of the "p" element ...

Using ngFor directive to iterate through nested objects in Angular

Receiving data from the server: { "12312412": { "id": "12312412", "something": { "54332": { "id": "54332", "nextNode": { "65474&q ...

Accessing clipboard contents upon button click using TypeScript

Seeking assistance with retrieving data from the clipboard in TypeScript after clicking on a button. Please provide guidance. Thank you! ...

When TypeScript tsc is unresponsive, there is no output or feedback provided

Just getting started with TypeScript! I've been working on transitioning my React.js project from JavaScript to TypeScript. I managed to resolve all the bugs and verified that it runs smoothly when using npm start. However, whenever I try to comp ...

The Angular translation service may encounter issues when used on different routes within the application

I'm currently working on an Angular application that has multi-language support. To better organize my project, I decided to separate the admin routes from the app.module.ts file and place them in a separate file. However, after doing this, I encounte ...

Is it possible to eliminate the arrows from an input type while restricting the change to a specific component?

Is there a way to remove the arrows from my input field while still applying it only to the text fields within this component? <v-text-field class="inputPrice" type="number" v-model="$data._value" @change="send ...

The value of req.headers('Authorization') has not been defined

I'm experiencing difficulty with my code as the token is coming back as undefined. Here is the frontend section: export const fetchUser = async (token: any) => { const res = await axios.post('/user/getuser', { headers ...

create the text with double bold - adjusted pages

Is there a method to enhance the boldness of the text without adjusting the font size? Currently, the following styling is applied: numbers: { fontSize: 30, color: '#31C283', fontWeight: 'bold', }, Is there a way to m ...

Retrieving information from a Kendo grid cell

I am working on a web application that utilizes Kendo Grid. How can I retrieve the values of the "Ticket No" from the selected checkboxes? https://i.stack.imgur.com/aPOje.png This is my code: var grid = $("#poGrid").data("kendoGrid"); grid.items().filte ...

Using aliases for importing will not function in the Vite (React, Typescript) starter template

I had installed shadcn/ui into my vite boilerplate as per the documentation, but ran into issues with the compiler not recognizing the aliasing. I discovered that TypeScript utilizes multiple configuration files - tsconfig.json, tsconfig.app.json, and tsco ...

What is the process for converting this example into a TypeScript class?

Currently in the process of developing an application using the H5P plug-in, I came across the need to create something for the H5P editor. This led me to discover this documentation on implementing a widget. /** * Module for Color selector widget * * @ ...

The element 'x' is implicitly bound with a type of 'any'

I've been exploring the world of Nextjs and TypeScript in an attempt to create a Navbar based on a tutorial I found (). Although I've managed to get the menu items working locally and have implemented the underline animation that follows the mou ...

What is the process for loading a model using tf.loadModel from firebase storage?

I'm currently working on an app using the ionic3 framework that recognizes hand-drawn characters. However, I am encountering difficulties with importing the model into my project. The model was initially imported from Keras and converted using tensorf ...

Issues with Angular's router outlet link functionality not performing as expected

I am encountering difficulties trying to create a link to a named router outlet in Angular. Let's focus on the most crucial part of the code: app-routing-module.ts: import { NgModule } from '@angular/core'; import { RouterModule, Routes } ...

Angular is throwing error TS2322 stating that the type 'string' cannot be assigned to the type '"canvas" while working with ng-particles

My goal is to incorporate particles.js into the home screen component of my project. I have successfully installed "npm install ng-particles" and "npm install tsparticles." However, even after serving and restarting the application, I am unable to resolve ...

Issue with TypeScript in VSCode: "Unable to save file 'x' as it would overwrite the input file."

As I work on improving my JavaScript quality with TypeScript in VSCode, I’m encountering an issue with my tsconfig.json file. It keeps throwing errors when trying to write my .js files, specifically displaying the message: "Cannot write file 'lib/c ...

Encountering a Typescript error when attempting to access the 'submitter' property on type 'Event' in order to retrieve a value in a |REACT| application

I am facing an issue with my React form that contains two submit buttons which need to hit different endpoints using Axios. When I attempt to retrieve the value of the form submitter (to determine which endpoint to target), I encounter an error while work ...