When is $A\otimes R$ a free $R$-module? Let $R$ be a commutative ring. If I am not mistaken, there is the following fact:

For a finitely generated abelian group $A$, the $R$-module $A\otimes R$ is free if and only if we can write the torsion part of $A$ as a direct sum of cyclic groups of the form $\mathbb{Z}/k$, where $k$ is invertible or zero in $R$ 

While elementary, I found this surprisingly tricky to prove and my proof takes about half a page. But I assume, this fact should be known. As I need it for a paper of mine, I want to ask whether someone knows a reference for it. In absence of a reference, I would also be happy with a slick 5-line proof! 
 A: Here is a 7-line proof of your statement.


Claim. Let $R$ be a commutative ring with identity $1_R$. Let $A \simeq \mathbb{Z}/d_1\mathbb{Z} \oplus \cdots \oplus \mathbb{Z}/d_k\mathbb{Z}$ be a finitely generated Abelian group given with its invariant factor decomposition, i.e., $d_i \ge 0, d_i \neq 1$ and $d_i$ divides $d_{i + 1}$ for every $1 \le i \le k - 1$ (note that $d_i = 0$ is allowed).
Then $A \otimes_{\mathbb{Z}} R$ is free over $R$ if and only if either $d_i 1_R$ is zero or a unit of $R$ for every $i$.
Proof (7 lines). Let $M \Doteq A \otimes_{\mathbb{Z}} R \simeq 
R/d_1 R \oplus \cdots \oplus R/d_k R$. If $d_i 1_R$ is zero or a unit of $R$ for every $i$, then $M$ is clearly free over $R$. Assume now that $M$ is free over $R$. We reason by contradiction and consider the smallest $j \ge 1$ such that $d_j 1_R$ is neither zero nor a unit. Then we have  $M \simeq R/d_j R \oplus \cdots \oplus R/d_k R$. Considering $M/\mathfrak{m}M$ for a maximal ideal $\mathfrak{m}$ which contains $d_jR$, we see that the minimal number of generators of $M$ over $R$ is $s \Doteq k -j + 1$. Therefore $M \simeq R^s$ and consequently $d_jM$ cannot be generated by less than $s$ elements. As $d_jM \simeq 
(d_jR/d_{j + 1} R) \oplus \cdots \oplus (d_jR/d_k R)$, we get a contradiction.


You may turn the above proof into a one-liner if you refer to this more general result of Irving Kaplansky [1, Theorem 9.3].


Kaplansky's Theorem. 
    Let $R$ be a ring in which every one-sided ideal is two-sided. In particular, $R$ may be any commutative ring. Suppose the $R$-module $M$ is isomorphic to the direct sum of cyclic modules $R/S_1, \dots, R/S_m$, and also to the direct sum of $R/T_1, \dots, R/T_n$, where $S_i,\, T_¡$ are ideals each containing its successor, $S_1, T_1\neq R$. Then $m = n$ and $S_i = T_i$ for all $i$.



Addendum. I found the discussion of Qiaochu Yuan and YCor about projective modules (see comments above) particularly enlightening. This is why I would like to assemble all its fragments here.


Qiaochu Yuan's Claim on projectives. Let $R$ be a commutative ring with identity and let $A$ be a direct sum of cyclic groups $\mathbb{Z}/k_i\mathbb{Z}$ where $k_i \in \mathbb{Z}$ and $i$ ranges in some arbitrary set.
    Then $A \otimes_{\mathbb{Z}} R$ is a projective module over $R$ if and only if $k_iR = k_i^2R$ for every $i$.
Proof. Let $M \Doteq A \otimes_{\mathbb{Z}} R \simeq 
\bigoplus_i R/k_i R$. Then $M$ is projective over $R$ if and only if $R/k_iR$ is projective for every $k$. This holds if and only if the natural map $R \twoheadrightarrow R/k_iR$ splits for every $i$, which is in turn equivalent to the fact that $k_iR$ is an idempotent ideal. As observed by YCor, $k_iR$ is generated by an idempotent in this case, see e.g, [2, Exercise 2.1], a classical application of Nakayama's lemma.


If $\mathbb{Z}1_R \simeq \mathbb{Z}/n\mathbb{Z}$ for some $n > 1$, then 
the condition $\text{gdc}(k, n) = \text{gdc}(k^2, n)$, or equivalently $\text{gcd}(k, \frac{n}{\text{gcd}(n, k)}) = 1$, implies $kR = k^2R$. This is certainly a necessary condition when $R = \mathbb{Z}/n\mathbb{Z}$.
YCor outlined the fact that every module over $\mathbb{Z}/6\mathbb{Z}$ is projective. He further extends this remark by mentioning below that every module over a commutative ring $R$ with identity is projective if and only if $R$ is the direct product of finitely many fields, see this MO post for references and a more general statement. 


Remark on projective modules over $\mathbb{Z}/n\mathbb{Z}$. Let $n$ be a positive integer. Then the following are equivalent:

  
  
*
  
*The integer $n$ has no square factor.  
  
*Every module over $\mathbb{Z}/n\mathbb{Z}$ is projective.  

Proof. By the first Prüfer Theorem, a module over $R = \mathbb{Z}/n\mathbb{Z}$ is a direct sum of cyclic factors $\mathbb{Z}/k\mathbb{Z}$ where $k$ divides $n$. If $n$ is square-free, any such factor is projective over $R$ by Qiaochu Yuan's Claim. Hence any module over $R$ is projective. If $n$ has a square factor $k^2$ with $k > 1$, then $R/kR$ is not projective over $R$ by Qiaochu Yuan's Claim.



[1] I. Kaplansky, "Elementary divisors and modules", 1949.
[2] H. Matsumura, "Commutative Ring Theory", 1986.
