terraform basics

resource – fundamental element to provision a resource in the cloud , so lets say you want to deploy a snow flake masking policy resource in the cloud ( complicated example , i know , but bear with me ) . This resource definition can be found here

https://registry.terraform.io/providers/chanzuckerberg/snowflake/latest/docs/resources/masking_policy

resource "snowflake_masking_policy" "example_masking_policy" {
  name               = "EXAMPLE_MASKING_POLICY"
  database           = "EXAMPLE_DB"
  schema             = "EXAMPLE_SCHEMA"
  value_data_type    = "string"
  masking_expression = "case when current_role() in ('ANALYST') then val else sha2(val, 512) end"
  return_data_type   = "string"
}

the first string after the key word resource identifies this to be a snowflake masking policy . The second name is the variable name example_masking_policy that is how terraform will identify this in state and definition. The curly brackets enclose the properties for the resource , so in this case the name of the policy , the database where this would be created, the schema etc will have to defined here .

so here are the high level steps in running terraform

Terraform init – this is the first command you need to run , this pulls the provider information, modules ( we will get to this later ) and stores it in the directory where this command is run

Terraform validate – this command check if the resource definition is syntatically correct

Terraform Plan – this gives an output of what changes will be applied ( or removed ) with the current config file. This steps parses through the current file , checks and refreshes the state file, compare the difference between the config and the state file and calculates what needs to be applied.

Terraform apply – this is the final step to apply the changes identified in the previou step

Terraform destroy – this will wipe out everything

now lets talk about modules – this is where you can combine multiple resource definition file and deploy it as a module , so in the snowflake scenario , you can deploy one module that can deploy databases and associated schemas . This can have an associated variables.tf file and the module can deploy the resources that these variables assume the corresponding value. Now in the main.tf file , we can set the corresponding variables that are for your specific instance . Modules thus give us a way to come up with a generic but standard template to deploy our infrastructure.

Debugging tips for react native application

Here are some different ways to debug a react native application .

  • use console.log (“debug message”) . Using this you can open up the console and see what sections of the code is being executed and what the values are for the variables etc. This is simple , but painful to code all of these debug statements
  • The second method would be to enable remote debugging and use chrome to debug the react native app. Basically open up the simulator , load the menu in the expo client and enable remote debugging. This will open up a chrome session and now you can leverage chrome to debug the source code . You can use the source tab and set breakpoint, set watch variables, use the network tab to look at api calls etc . Make sure to select the pause on caught exceptions and reload the app

  • use the debug configuration within vs code and leverage vs code to debug the java script, Ensure the debug configuration is set to attach to packager and the react native port is set correctly -> in my case it came up to 19000 , the default is 8081 . You cannot use the vs code and chrome at the same time , since the same port is being used
  • Click on the debug icon , create a launch.json file , select the react native environment

select the options

this will create the debug configuration , these configuration can now be accessed in the debug menu – select attach to packager

and then select the green play button and this should start the debugger

go to settings and change the port for react-native packager port

if you run into an error like this

you may have a chrome session open to the port and you should close the browser that says react native debugger and has this in the address link http://localhost:19000/debugger-ui/

now when you run the debug configuration , you should see the screens with the debug session active and now you can use vscode to look at the error

once you are done with debugging , click on the chain icon to stop the debug session and in the expo menu , disable remote debugging and reload the application.

first steps to build react native app

install expo , we will use this to get started with the project the command is as follows

sudo npm i -g  expo-cli

install expo client on your phone

install vs code , react native tools extension , react snippet and prettier extensions

update node

  • npm cache clean -f
  • npm install -g npm
  • sudo npm install -g n
    • the above command installs n. – which is the node version manager , use this to update node
  • sudo n stable
  • verify the version of node

expo-cli has a prerequisite on the node version , make sure the version you have is supported by expo-cli

expo init prjrntestapp

this will give you an option to select workflow , in this case select the blank workflow to start off with the most basic configuration

this will come up with a message stating your project is ready , you can cd into the folder and start vs code by typing code . in that directory

go to the terminal from vscode and type in

npm start

this should start the expo bundler and it will give options to run the app in ios , android or web .

start up xcode on your mac and open up simulator for iphone and run the same

from the terminal you can type expo start if you are disconnected , this should give you a screen like the one below

select i for open ios simulator , a one line display in the simulator with the same text as in app.js will be displayed here.

You can now modify the app.js and this should give you the initial screen

control-d and command -D in case you want to see the menu , in any case here is the first screen

next step is to run it in android simulator. , you do need android studio for the same , so install the same with the default standard options and that should include the simulator

make sure you can run adb android debugger from command line , modern mac os has the zsh shell so modifying the bash_profile file is not enough , you need to modify the zsh as well. Make sure you restart the terminal for the new profile settings to take effect before running adb

use avd manager. – android virtual device manager to create a new device to test the app on , select latest pixel with the play store installed to get one created

select the image and then it should build the device , select the play button under actions and it should bring up the emulated device

in the terminal in vs code where you have the expo running , select a for android and it should install and open up the expo client in the virtual device ..you should see something like this in the terminal

Logs for your project will appear below. Press Ctrl+C to exit.
› Opening on iOS…
› Opening exp://127.0.0.1:19000 on iPhone 12 Pro Max
iOS Bundling complete 16923ms
iOS Running app on iPhone 12 Pro Max
› Press ? │ show all commands
› Opening on iOS…
› Opening exp://127.0.0.1:19000 on iPhone 12 Pro Max
› Press ? │ show all commands
› Opening on Android…
› Opening exp://192.168.1.230:19000 on
› Press ? │ show all commands
Android Bundling complete 19493ms
Android Running app on Android SDK built for x86

you can press command + M to bring up the developer menu on the mac ( ctrl + m on windows )

to bring the app on your phone , click on the expo client ( make sure you have this downloaded from the app store ) , scan the QR code and it should bring up your app on the phone , it does require you to be on the same wireless network as your expo server.

you can shake the phone and it can bring up the developer menu