awk - use fields from subsequent lines

I've run into a problem getting exactly what I want out of awk - some folks may recognize this as an output from Amazon's ec2-describe-instances:

Given the following:
INSTANCE i-4960f321
BLOCKDEVICE Line2Var2
TAG instance i-4960f321 Name web1
TAG instance i-4960f321 aws:autoscaling:groupName web1asg
INSTANCE i-4960f322
BLOCKDEVICE Line6Var2
TAG instance i-4960f322 Name web2
TAG instance i-4960f322 aws:autoscaling:groupName web2asg
INSTANCE i-4960f320
BLOCKDEVICE Line10Var2
TAG instance i-4960f320 Name app1

The desired output is:
$2 (from the INSTANCE line), $5 (from the first TAG line) or NULL, $5 (from the second TAG line) or NULL.

Example:
i-4960f321 web1 web1asg
i-4960f322 web2 web2asg
i-4960f320 app1 NULL

CJ

P.S. If folks are interested, if I find something helpful here I'm planning on using for a suite of Amazon Web Service related tools called aws missing tools (Google for it - fourth link).

Try this:

awk '
    /^INSTANCE/ {
        if( instance )
            printf( "%s %s %s\n", instance, tags[0], tags[1] ? tags[1] : "NULL" );
        instance = $2;
        tidx = 0;
        delete tags;
        next;
    }
    /^TAG / {
        tags[tidx++] = $5;
        next;
    }
    END {
        printf( "%s %s %s\n", instance, tags[0], tags[1] ? tags[1] : "NULL" );
    }
' input-file

Here is another:

$

awk '/INSTANCE/{a=$2} /TAG/{if($4=="Name"){b=$5;getline} else{b="NULL";} {if($0 ~ "TAG"){print a,b,$5}else {print a,b,"NULL";a=$2}}}' /tmp/input

Here is my /tmp/input file: