An easy way is to use the fit
library along with a local bounding box
.

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}
\begin{scope}[rotate=-{30},local bounding box=a]
\draw (0,0)--(0,4)--(4,4)--(4,2)--(6,2)--(6,0)--(4,0)--(4,-2)--(2,-2)--(2,0)--cycle;
\draw (2, 0)--++(2,0);
\draw (0, 2)--++(4,0);
\draw (2,4)--++(0,-4);
\draw (4,2)--++(0,-2);
\end{scope}
\node [fit=(a),inner sep=0pt,draw] {};
\end{tikzpicture}
\end{document}
Or, given the local bounding box
, use a rectangle
path:
\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\begin{scope}[rotate=-{30},local bounding box=a]
\draw (0,0) |- (4,4) |- (6,2) |- (4,0) |- (2,-2) |- cycle;
\draw (4, 0) -| (2,4)
(0,2) -| (4,0);
\end{scope}
\draw (a.south west) rectangle (a.north east);
\end{tikzpicture}
\end{document}
(This shows the use of -|
/|-
paths to cut the number of coordinates in half.)
If drawing the same lines more than once isn't a problem, you could use a loop like this to draw the shape:
\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\begin{scope}[rotate=-{30},local bounding box=a]
\foreach \x/\y in {1/0,0/1,1/1,2/1,0/2,1/2} % list of rectangle centers
\draw (\x-0.5, \y-0.5) rectangle ++(1,1);
\end{scope}
\draw (a.south west) rectangle (a.north east);
\end{tikzpicture}
\end{document}
Addendum
Perhaps the easiest way to achieve your additional requirements is to use nodes to make the squares, and a fit
node to make the rectangle. By filling the nodes with white, and using on background layer
to fill the fit
node with some other colour, you get the appearance you're asking for. If you actually want to fill only the area between shape and rectangle you need to use \clip
in a scope
, and I'd actually suggest asking a new question.
Because everything is a node, drawing lines between inner squares and outer rectangle is easy, just use the node anchors as coordinates.

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{backgrounds,fit}
\begin{document}
\begin{tikzpicture}
\begin{scope}[rotate=-{30},local bounding box=a]
\foreach [count=\i] \x/\y in {1/0,0/1,1/1,2/1,0/2,1/2} % list of rectangle centers
\node [transform shape, % allow for rotation
draw, % draw outline
fill=white, % fill with white
minimum size=1cm, % set size
name=n-\i,
%label=center:n-\i % if you want to see the names of the nodes, uncomment this
] at (\x-0.5, \y-0.5) {};
\end{scope}
\scoped[on background layer] % the following path is on the background layer
\node [draw=black, fill=blue!10, fit=(a), inner sep=0.2pt, name=frame] {};
\draw [-latex] (frame.280) to[bend right] (n-1);
\draw (frame.east) -- (n-3.north east);
\end{tikzpicture}
\end{document}
\draw (0,0) rectangle ++(2,2) (2,0) rectangle ++(2,2) (0,-2) rectangle ++(2,2) (2,-2) rectangle ++(2,2) (4,-2) rectangle ++(2,2) (2,-4) rectangle ++(2,2);
also draws the shape.